Newbie: text filtering.

olivier migeon olivier at phgroup.com
Mon Aug 7 08:26:09 EDT 2000


Use re.
This should do it:

import re

mre=re.compile(r"\b(?P<filename>.*)\.pdf\b",re.I)

def mparse(mstring):
    xx=mre.search(mstring)
    if xx:
        return xx.group('filename')
    else:
        print 'no match'
        return None

if __name__=="__main__":
      a="myfile1.pdf  mydescription"
      print mparse(a)

HTH
o-m.

Aesop wrote:

> How could I go about say searching for the ".pdf", then working
> backwards to find the start of the word?




More information about the Python-list mailing list