2

I need some help to write a reg exp to find times in the following format 00:00 and 0:00 (up to max value 23:59)

NSPredicate *timePredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES ??"];
NSArray *filteredArray = [someArray filteredArrayUsingPredicate:timePredicate];
GEOCHET
  • 21,119
  • 15
  • 74
  • 98
Anders Öhrn
  • 47
  • 1
  • 4

1 Answers1

1

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.

Community
  • 1
  • 1
Staffan Nöteberg
  • 4,095
  • 1
  • 19
  • 17