Skip to content

Instantly share code, notes, and snippets.

@stefanluptak
Created March 11, 2011 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanluptak/865952 to your computer and use it in GitHub Desktop.
Save stefanluptak/865952 to your computer and use it in GitHub Desktop.
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