Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I parse a file name format like 'PUBLIC001' with a Regular Expression?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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}$
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading