Re: [Tutor] Matching multiple regular expressions

2005-01-12 Thread Bill Campbell
On Wed, Jan 12, 2005, Tzu-Ming Chern wrote: > >Hi Python Tutors, > >Is there a more elegant solution to matching multiple regular expressions? > >An example would be: > >lista = ['hello','goodbye','bubblegum'] # lista would contain my regular >expressions I want to match > >My file would look som

Re: [Tutor] Matching multiple regular expressions

2005-01-12 Thread Orri Ganel
Kent Johnson wrote: Just join the individual strings together with | to make a single regex, then search each line for a match: >>> import re >>> lista = ['hello','goodbye','bubblegum'] >>> regex = re.compile('|'.join(lista)) >>> lines = '''line1: blah blah aldkfslfjlajf hello ... line2: bla

Re: [Tutor] Matching multiple regular expressions

2005-01-12 Thread Kent Johnson
Just join the individual strings together with | to make a single regex, then search each line for a match: >>> import re >>> lista = ['hello','goodbye','bubblegum'] >>> regex = re.compile('|'.join(lista)) >>> lines = '''line1: blah blah aldkfslfjlajf hello ... line2: blah blah dkajfldjfjkds

[Tutor] Matching multiple regular expressions

2005-01-12 Thread Tzu-Ming Chern
Hi Python Tutors, Is there a more elegant solution to matching multiple regular expressions? An example would be: lista = ['hello','goodbye','bubblegum'] # lista would contain my regular expressions I want to match My file would look something like this: line1: blah blah aldkfslfjlajf hello