RegexKitLite 使用

| No Comments | No TrackBacks

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.");

}

}

No TrackBacks

TrackBack URL: http://iphone.ipsw.info/mt/mt-tb.cgi/301

Leave a comment