Created
January 2, 2014 18:52
-
-
Save sartak/8224422 to your computer and use it in GitHub Desktop.
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
NSError *regexError = nil; | |
NSRegularExpression *nameRegex = [NSRegularExpression regularExpressionWithPattern:@"^Name:\\s*?(.+)" | |
options:NSRegularExpressionCaseInsensitive | |
error:®exError]; | |
if (!nameRegex) { | |
NSLog(@"REGEX ERROR: %@", regexError); | |
} | |
__block NSString *name = nil; | |
[nameRegex enumerateMatchesInString:input | |
options:0 | |
range:NSMakeRange(0, [input length]) | |
usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) { | |
if ([result numberOfRanges] > 1) { | |
NSRange range = [result rangeAtIndex:1]; | |
name = [input substringWithRange:range]; | |
} | |
(*stop) = YES; | |
}]; | |
NSLog(@"Name: %@", name); | |
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
my ($name) = $input =~ /^Name:\s*?(.+)/i; | |
warn "Name: $name"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment