Skip to content

Instantly share code, notes, and snippets.

@nomothetis
Created September 26, 2011 19:25
Show Gist options
  • Save nomothetis/1243140 to your computer and use it in GitHub Desktop.
Save nomothetis/1243140 to your computer and use it in GitHub Desktop.
Search-and-replace with Regexes in Objective-C.
NSError *err = nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"%%.*?%%" options:0 error:&err];
if (!regex) {
[NSException raise:@"badRegularExpression"
format:@"The regular expression was incorrectly constructed. Error was: %@", err];
}
[regex replaceMatchesInString:aMutableString options:0 range:NSMakeRange(0, newURL.length) withTemplate:@""];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment