删除两个字符之间的字符串

Jan*_*nub 3 objective-c ios

这是我的示例字符串

(括号)中的字符串(删除)

我想删除括号内的所有单词以及括号对,之后字符串将如下所示:

字串在中

Oma*_*ith 8

使用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)