J'essaie d'enlever une partie de la chaîne entre parenthèses. Par exemple, pour la chaîne "(This should be removed) and only this part should remain"
, après l'utilisation de NSRegularExpression, il doit être "and only this part should remain"
.Comment supprimer le texte entre parenthèses en utilisant NSRegularExpression?
J'ai ce code, mais rien ne se passe. J'ai testé mon code regex avec RegExr.com et cela fonctionne correctement. J'apprécierais toute aide.
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);
Cochez cette case. http://stackoverflow.com/questions/3741279/how-do-you-remove-parentheses-words-within-a-string-using-nsregularexpression?rq=1 –