使用reg表达式删除字符串如下所示(这@"\\(.+?\\)"是(和)之间字符串的正则表达式)
NSMutableString *str = [@"String of words in (brackets) to be (removed)" mutableCopy];
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:@"\\(.+?\\)"
options:NSRegularExpressionCaseInsensitive
error:NULL];
[regex replaceMatchesInString:str
options:0
range:NSMakeRange(0, [str length])
withTemplate:@""];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3081 次 |
| 最近记录: |