我正在尝试从src替换src的图像。我还需要在文档目录中保存图像。 我试过以下代码。但没有运气。
NSError *error = NULL;
NSRegularExpression *regex =[NSRegularExpression regularExpressionWithPattern:@"(<img\\s[\\s\\S]*?src\\s*?=\\s*?['\"](.*?)['\"][\\s\\S]*?>)+?" options:NSRegularExpressionCaseInsensitive error:&error];
[regex enumerateMatchesInString:str_TotalString
options:0
range:NSMakeRange(0, [str_TotalString length])
usingBlock:^(NSTextCheckingResult result, NSMatchingFlags flags, BOOL stop) {
NSString *img=[str_TotalString substringWithRange:[result rangeAtIndex:2]];
NSLog(@"img src %@",img);
NSUInteger numberOfMatches = [regex numberOfMatchesInString:str_TotalString options:0 range:NSMakeRange(0, [str_TotalString length])];
if (abc==0)
{
[self saveTODOC:img:0];
}
else
{
[self saveTODOC:img:abc];
}
str_TotalString=[str_TotalString stringByReplacingOccurrencesOfString:img withString:imgHTMLTag_Replace];
NSLog(@"Found %lu",(unsigned long)numberOfMatches);
}];
任何帮助,请