I'm currently trying to match phrases like mexico 1 - 2 cameroon using regex, it matches when using regexpal to test the regex, but no match in Python using re.
My regex is:
regex = '(mexico[\s]*\d[\s]*[-][\s]*\d[\s]*cameroon)|(mexico[\s]*\d[\s]*cameroon[\s]\d)|(mexico[\s]*\d[\s]*[-][\s]*cameroon[\s]*\d)|(cameroon[\s]*\d[\s]*[-][\s]*\d[\s]*mexico)|(cameroon[\s]*\d[\s]*mexico[\s]\d)|(cameroon[\s]*\d[\s]*[-][\s]*mexico[\s]*\d)'
and my test phrase:
testphrase = RT @remitouja: @TheJUMPsociety cameroon 1 - 1 mexico #winecup #WorldCup"
I successfully match in regexpalbut not python, but the testphrase doesn't. But the following matches in both:
cameroon 1 - 1 mexico #winecup #WorldCup
Using
if re.match(regex, testtweet) is not None:
print "Is true"
to test
re.matchwhile you should be usingre.search.regex = r'(mexico...'