RegexKitLite 之前搞过,但是内弄清楚,这次必须搞好。
下面是测试代码,在SDK 4.0 上通过。3.2一下NSRegularExpressionSearch 不支持,自己想办法吧。
-(void)test
{
NSString *html=[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"1.html" ofType:nil] encoding:NSUTF8StringEncoding error:nil];
//NSString *exp=@"/(https?)://(\\d+))?((?:/[a-zA-Z0-9\\-._?,'+\\&%$=~*!():@\\]*)+)?/";
NSString *exp=@"http://[^ ]*.(png|jpeg|PNG|JPEG|JPG|jpg)";
NSRange r;
for(NSString *match in [html componentsMatchedByRegex:exp]) {
NSLog(@"111Phone number is %@", match);
}
r = [html rangeOfString:exp options:NSRegularExpressionSearch];
if (r.location != NSNotFound) {
NSLog(@"Phone number is %@", [html substringWithRange:r]);
} else {
NSLog(@"Not found.");
}
}

Leave a comment