Reputation: 1989
I need some suggestions in writing a regular expression pattern
My string would be of this format
number_text_date_time.xml
i.e.: 35068_Started_20110304_081920.xml
Number 5 characters ,"Text" can be of this format, "Date" in yyyymmdd format, "time" in HHMMSS format
One requirement I have is, the TEXT in the name of the file has to be checked against a predefined list. Ex: Text can contain only STARTED, CLOSED, OPENED, NOT-OK etc
How can I write a Generic expression for this considering the fact that I also have to check the TEXT against predefined list
Thank in advance
Karthik
Upvotes: 1
Views: 102
Reputation: 25563
Not fully tested; line breaks for clarity only:
(?<number>\d{5})_
(?<text>STARTED|CLOSED|OPENED|NOT-OK)_
(?<date>(19|20)[0-9]{2}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01]))_
(?<time>(20|21|22|23|[0-1]\d)[0-5]\d[0-5]\d).xml
I turned on the Case Insensitive option to match your string.
With help from RegexBuddy and http://regexlib.com/
Upvotes: 2