This is what you are looking for, I think:
NSString *myString = @"John @ 123-456-7890";
NSString *myRegex = @"\\d{3}-\\d{3}-\\d{4}";
NSRange range = [myString rangeOfString:myRegex options:NSRegularExpressionSearch];
NSString *phoneNumber = nil;
if (range.location != NSNotFound) {
phoneNumber = [myString substringWithRange:range];
NSLog(@"%@", phoneNumber);
} else {
NSLog(@"No phone number found");
}
You can rely on Cocoa's default regular expression lookup engine. Thus, you can extract the range corresponding to the phone number, if any.
Remember that when creating regular expressions always execute double backslashes.
Adapt the regular expression to the part of the phone number you want to extract.
Cocoa . RegexKitLite Cocoa.