omrakhur omrakhur - 1 year ago 151
Python Question

Python 3 - Regular expression for a set digit length?

I want to check if another string matches with the following string:

'abc_xxxxxxxxxxxxx.txt'


e.g.

abc_20170926121600.txt
would match

but

xyz_20170926121600.txt
or
abc_201709261216002323232323232323.txt
would not match

Answer Source

You want this:

abc_\d{N}\.txt

Where N is the number of digits.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download