Я пытаюсь удалить часть строки, которая находится в круглых скобках.Как удалить текст в круглых скобках с помощью NSRegularExpression?
В качестве примера, для строки "(This should be removed) and only this part should remain"
, после использования NSRegularExpression это должно стать "and only this part should remain"
.
У меня есть этот код, но ничего не происходит. Я проверил код регулярного выражения с RegExr.com, и он работает правильно. Буду признателен за любую помощь.
NSString *phraseLabelWithBrackets = @"(test text) 1 2 3 text test";
NSError *error = NULL;
NSRegularExpression *regexp = [NSRegularExpression regularExpressionWithPattern:@"/\\(([^\\)]+)\\)/g" options:NSRegularExpressionCaseInsensitive error:&error];
NSString *phraseLabelWithoutBrackets = [regexp stringByReplacingMatchesInString:phraseLabelWithBrackets options:0 range:NSMakeRange(0, [phraseLabelWithBrackets length]) withTemplate:@""];
NSLog(phraseLabelWithoutBrackets);
Проверьте это. http://stackoverflow.com/questions/3741279/how-do-you-remove-parentheses-words-within-a-string-using-nsregularexpression?rq=1 –