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

Regex to find all folders that have 10 integers

I have a parent folder Z:\data\ containing subfolders as follows:

Z:\data\8346835623\
Z:\data\8346835623\
...
Z:\data\clicks\
Z:\data\useless\
...

What regex expression should I use to get the folders that are named as integers?

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 :

You can use the character class \d to specify ‘a digit (0-9)’ followed by the quantifier {10} to specify ‘exactly 10 of…’

Assuming everything is in Z:\data\, this pattern should match the files you want

Z:\\data\\\d{10}\\

The additional backslashes are used to escape the literal backslash characters in the path.

Here’s the verbatim explanation from https://regex101.com

Z: matches the characters Z: literally (case sensitive)

\ matches the character \ with index 9210 (5C16 or 1348) literally (case sensitive)

data matches the characters data literally (case sensitive)

\ matches the character \ with index 9210 (5C16 or 1348) literally (case sensitive)

\d matches a digit (equivalent to [0-9])

{10} matches the previous token exactly 10 times

\ matches the character \ with index 9210 (5C16 or 1348) literally (case sensitive)

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