- (void)initImg:(UIWebView*)webView{
NSString*html = [[NSStringalloc]initWithContentsOfURL:webView.request.URLencoding:NSUTF8StringEncodingerror:nil];
NSRegularExpression*regex = [NSRegularExpressionregularExpressionWithPattern:@"<img[^>]* src[^>]*/>"options:NSRegularExpressionAllowCommentsAndWhitespaceerror:nil];
NSArray*result = [regexmatchesInString:htmloptions:NSMatchingReportCompletionrange:NSMakeRange(0, html.length)];
for(NSTextCheckingResult*iteminresult) {
NSString*imgHtml = [htmlsubstringWithRange:[itemrangeAtIndex:0]];
if([imgHtmlrangeOfString:@"src="].location!=NSNotFound) {
NSRangerangeSrc = [imgHtmlrangeOfString:@"src="];
NSRangerangeJpg = [imgHtmlrangeOfString:@".jpg"];
if((rangeJpg.location- rangeSrc.location-@"src=".length+@".jpg".length-1) <= imgHtml.length){
NSString*str = [imgHtmlsubstringWithRange:(NSMakeRange(rangeSrc.location+@"src=".length+1, rangeJpg.location- rangeSrc.location-@"src=".length+@".jpg".length-1))];
NSLog(@"正確解析出來的SRC為:%@", str)洞焙;
}
}
}
}