Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Prints first match of text in parenthesis
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"id=([0-9]+)" options:NSRegularExpressionCaseInsensitive error:&error];
NSTextCheckingResult *result = [regex firstMatchInString:str options:NSMatchingReportCompletion range:NSMakeRange(0, [str length])];
NSLog(@"%@", [str substringWithRange:[result rangeAtIndex:1]]); // prints 123 for "id=123"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.