Created
July 9, 2012 08:51
-
-
Save isutton/3075205 to your computer and use it in GitHub Desktop.
Regular expressions in Objective-C
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
#import <Foundation/Foundation.h> | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
NSString *key = @"UINavigationBarTintColor"; | |
NSString *pattern = @"(Color|Font|Height|Width|Size|Origin|Frame)$"; | |
NSError *error = nil; | |
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:NSRegularExpressionCaseInsensitive error:&error]; | |
if (regex) { | |
// Regular expression pattern is valid, let's check if we can find a match in the string. | |
NSTextCheckingResult *match = [regex firstMatchInString:key options:0 range:NSMakeRange(0, [key length])]; | |
NSString *matchString = [key substringWithRange:match.range]; | |
NSLog(@"matchString: %@", matchString); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment