pattern match !

Asun Friere afriere at yahoo.co.uk
Sun Jul 15 22:24:59 EDT 2007


On Jul 11, 9:29 pm, Helmut Jarausch <jarau... at igpm.rwth-aachen.de>
wrote:
> import re
> P=re.compile(r'(\w+(?:[-.]\d+)+)-RHEL3-Linux\.RPM')
> S="hpsmh-1.1.1.2-0-RHEL3-Linux.RPM"
> PO= P.match(S)
> if  PO :
>    print PO.group(1)

Isn't a regexp overkill here when this will do:

head = filename[:filename.index('-RHEL3')]

Of course if you need to make it more generic (as in Jay's solution
below), re is the way to go.




More information about the Python-list mailing list