开发者

Time Regex in Cocoa

开发者 https://www.devze.com 2023-02-20 21:49 出处:网络
I need some help to write a reg exp to find times in the following format 00:00 an开发者_如何学Pythond 0:00 (up tomax value 23:59)

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

精彩评论

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