[Tutor] (no subject)

Alan Gauld alan.gauld at yahoo.co.uk
Fri Mar 22 20:37:09 EDT 2019


On 22/03/19 21:45, Matthew Herzog wrote:

> I need to tell my script to ignore any filename that does not conform to
> the standard eight leading numerical characters, example: 20180922 or
> erased_20171207_1oIkZf.so.

Normally we try to dissuade people from using regex when string methods 
will do but in this case a regex sounds like it might be the best option.

A single if statement should suffice

if re.match("[0-9]{8}|erased_",fname):
    Your code here

There are other ways to write the regex but the above should
be clear...

HTH,

Alan G.



More information about the Tutor mailing list