查找网站里面的文章是否包含“π”
2023-07-04 本文已影响0人
恶棍01
- (void)checkBoke {
NSString *url_str = @"https://blog.csdn.net/m0_61778720/article/details/123635034";
NSURL *url = [NSURL URLWithString:url_str];
NSError *error;
NSString *appInfoString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];
NSArray * config1 = [appInfoString componentsSeparatedByString:@"π"];
NSString * urlString = config1[1];
if (![urlString isEqualToString:URL_BaseURL]) {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:HOST_KEY];
CACHE_HOST(urlString) // REREAS默认环境设
}
}
/*!
NSString扩展了一个方法,通过正则获得字符串中的数据
*/
- (NSMutableArray *)getResultFromStr:(NSString *)str withRegular:(NSString *)regular {
if (str == nil) {
return NSMutableArray.new;
}
NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:regular options:NSRegularExpressionCaseInsensitive | NSRegularExpressionDotMatchesLineSeparators error:nil];
NSMutableArray *array = [NSMutableArray new];
// 取出找到的内容.
[regex enumerateMatchesInString:str options:0 range:NSMakeRange(0, [str length]) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
[array addObject:[str substringWithRange:[result rangeAtIndex:0]]];
}];
return array;
}