开发者

Time Regex in Cocoa

I need some help to write a reg exp to find times in the following format 00:00 an开发者_如何学Pythond 0:00 (up to max value 23:59)

NSPredicate *timePredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES ??"];
NSArray *filteredArray = [someArray filteredArrayUsingPredicate:timePredicate];


This should work in ICU regex, the syntax used in NSPredicate

\b(2[0-3]|[01]?\d):[0-5]\d\b

It looks for a word boundary \b followed by either 20-23, 00-19 or 0-9, then comes colon and finally 00-59 before another word boundary.

The word boundaries are important, since they prohibit matches of e.g. 123:456.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜