Skip to content

Instantly share code, notes, and snippets.

@joanromano
Created March 8, 2013 12:38
Show Gist options
  • Save joanromano/5116211 to your computer and use it in GitHub Desktop.
Save joanromano/5116211 to your computer and use it in GitHub Desktop.
Returns the NSRange of a given regular expression pattern
- (NSRange)rangeOfRegularExpressionPattern:(NSString *)pattern inString:(NSString *)string
{
NSRegularExpression *expression = [NSRegularExpression regularExpressionWithPattern:pattern options:nil error:nil];
NSTextCheckingResult *result = [expression firstMatchInString:string options:nil range:NSMakeRange(0, [string length])];
return result.range;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment