0

Can someone help me with what seems like a simple reg exp question? I am using python 2.7.13. I don't understand why the second test does not match

>>> p = re.compile("bananas")
>>> p.match("bananas123")
>>> <_sre.SRE_Match object at 0x1025aab28>
>>> p.match("123bananas")
>>>

(no match)

cperlmutter
  • 187
  • 2
  • 8

1 Answers1

4

You want re.search().

From the (DOCS)

Python offers two different primitive operations based on regular expressions: re.match() checks for a match only at the beginning of the string, while re.search() checks for a match anywhere in the string (this is what Perl does by default).

Stephen Rauch
  • 40,722
  • 30
  • 82
  • 105