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 to get files using Regex while excluding those that have sub/secondary file extension?

For example from the list of these files:

  • payload1.json
  • payload1.result.json
  • payload1.details.json
  • payload2.json
  • payload2.result.json
  • payload123.json
  • payload123.result.json
  • payload123.details.json
  • randomfile.gotincluded.byaccident.json
  • payload-001.json
  • some_data_for_processing.json

It should only return payload1.json, payload2.json, payload123.json, payload-001.json, and some_data_for_processing.json while ignoring everything else. Thanks!

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

>Solution :

^[a-zA-Z0-9_-]+.[a-zA-z0-9]+$

This will capture only the ones you want from that list.

^ : start of string
[ : beginning of character group
a-z : all characters a-z case sensitive
A-Z : all characters A-Z case sensitive
0-9 : all characters 0-9
_ : underscore
- : dash
] : end character group
+ : one or more of the character group
. : require a single .
[ : beginning of character group
a-z : all characters a-z case sensitive
A-Z : all characters A-Z case sensitive
0-9 : all characters 0-9
] : end character group
+ : one or more of the character group
$ : end of string
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