Need help with a regular expression that parses a file name
File will be named PUBLIC001
‘PUBLIC’ is static text in all file names
Last 3 digits- day of the year.001(Jan 1)-366(Dec31st on a leap year) is valid range
What would be regular expression. Is there a way to limit the max to 366?
THanks
>Solution :
A pattern like:
PUBLIC([0-2]\d\d|3[0-5]\d|36[0-6])
would do it.
Or if validating the date number doesn’t matter, then something like:
PUBLIC\d\d\d
or
PUBLIC\d{3}
would do it too.
Add a ^ and $ to the beginning and end, respectively, if the file should not have any other parts to it (e.g., this will avoid matching NOT-PUBLIC001, or PUBLIC001002)
like:
^PUBLIC\d{3}$