Using varible in re.match in python

Posted by screwuphead on Stack Overflow See other posts from Stack Overflow or by screwuphead
Published on 2013-10-19T03:33:47Z Indexed on 2013/10/19 3:53 UTC
Read the original article Hit count: 137

Filed under:
|
|
|

I am trying to create an array of things to match in a description line. So I cant ignore them later on in my script. Below is a sample script that I have been working on, on the side.

Basically I am trying to take a bunch of strings and match it against a bunch of other strings.

AKA: asdf or asfs or wrtw in string = true continue with script if not print this.

import re

ignorelist = ['^test', '(.*)set']

def guess(a):
     for ignore in ignorelist:
             if re.match(ignore, a):
                     return('LOSE!')
             else:
                     return('WIN!')

a = raw_input('Take a guess: ')
print guess(a)

Thanks

© Stack Overflow or respective owner

Related posts about python

Related posts about regex