Created
April 17, 2013 15:16
-
-
Save puls/5405155 to your computer and use it in GitHub Desktop.
Escaping a pattern doesn't do what you want
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int main(int argc, const char * argv[]) | |
| { | |
| @autoreleasepool { | |
| NSString *patternFromFile = @"/path/to/(something|theotherthing)"; | |
| NSRegularExpression *regex1 = [NSRegularExpression regularExpressionWithPattern:patternFromFile options:NSRegularExpressionCaseInsensitive error:nil]; | |
| NSRegularExpression *regex2 = [NSRegularExpression regularExpressionWithPattern:[NSRegularExpression escapedPatternForString:patternFromFile] options:NSRegularExpressionCaseInsensitive error:nil]; | |
| NSString *string = @"/path/to/something"; | |
| for (NSRegularExpression *regex in @[regex1, regex2]) { | |
| NSLog(@"matches: %ld", [regex numberOfMatchesInString:string options:0 range:NSMakeRange(0, string.length)]); | |
| } | |
| } | |
| return 0; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment