需求:在html中查找并替换相应的html标签
代码实现
- (NSString *)replaceImageHtml:(NSString *)oldHtml { NSString *regex = @"(<img.*?/>)"; NSRange r; NSMutableString *newHtml = [NSMutableString stringWithString:oldHtml]; BOOL flag = false; while (flag == false) { r = [newHtml rangeOfString:regex options:NSRegularExpressionSearch]; if (r.location != NSNotFound) { [newHtml replaceCharactersInRange:r withString:@""]; } else { flag = true; } }; return newHtml; }
ios-字符串替换-正则表达式-例子,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/anywherego/p/3821544.html