0

The pattern [aeiou][^vr]e(?=[^r]) works fine when testing at RegexPlanet.com, but when I use the same pattern with re.match in Python I get no matches.

import re
pattern = r'[aeiou][^vr]e(?=[^r])'
list = ['pale.', 'taste', 'kite']
for word in list:
    if re.match(pattern, word):
        print(word)

Expected Result:

pale.
kite.
Justin
  • 43
  • 5
  • `re.match`, [as documented](https://docs.python.org/3/library/re.html#re.match), requires the match to be **at the start of the string**. If you just want to know if there's a match *in* the string, use `re.search` instead. – jonrsharpe Jan 14 '18 at 17:36
  • Genius! Thank you. I was starting to go bald over something so simple. – Justin Jan 14 '18 at 17:39
  • Note you could have *read those docs*, or Googled your exact problem to find e.g. https://stackoverflow.com/q/16569067/3001761, https://stackoverflow.com/q/17680631/3001761, ... – jonrsharpe Jan 14 '18 at 17:41
  • My google-foo is not up to par. I greatly appreciate the help. – Justin Jan 14 '18 at 17:43

0 Answers0