Skip to content

Instantly share code, notes, and snippets.

@ksm
Created November 16, 2012 15:25
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 ksm/4088176 to your computer and use it in GitHub Desktop.
Save ksm/4088176 to your computer and use it in GitHub Desktop.
Extract date from natural language string
/*
Extract date from natural language string
Source: WWDC2012 Session 215 - Text and Linguistic Analysis
*/
NSDataDetector *dateDetector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeDate error:nil];
NSString *dateString = @"13th September 1986 11:59pm";
NSTextCheckingResult *result = [dateDetector firstMatchInString:dateString
options:0
range:NSMakeRange(0, [dateString length])];
if (result.resultType == NSTextCheckingTypeDate) {
NSLog(@"%@", result.date);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment