我有以下字符串:
@"Hello there, this is <em> a string. </em> Here's another scenario with tags, for example, <em> this </em>."
我需要删除<em>
和</em>
标记之间的所有内容,包括标记,因此结果应为:
@"Hello there, this is Here's another scenario with tags, for example, ."
如何使用正则表达式完成此操作?
答案 0 :(得分:3)
使用以下方法:
- (NSString *)stringByStrippingEMTag:(NSString *)str {
NSRange r;
NSString *s = [str copy];
while ((r = [s rangeOfString:@"<em[^>]*>(.*?)</em>" options:NSRegularExpressionSearch]).location != NSNotFound) {
s = [s stringByReplacingCharactersInRange:r withString:@""];
}
return s;
}