0

Just started learning Python regex, I was trying:

import re p='is' m='this is a test string' cp=re.compile(p) cp.match(m) print(cp.match(m))

I expected to get information related to the two "is" contained in the string but somehow the result was None.

Strange enough, when I tried to use matchall, I could get both substrings. I also tested the pattern on https://regex101.com/ and got the information related to the two "is" present in the message m.

I did notice that if the pattern is present at the beginning of the string it is matched. Eg. looking for 'th' generated the expected results.

Can someone help me understand what's happening!

Yelena
  • 423
  • 3
  • 14

0 Answers0