match.py 276 B

123456789101112
  1. import re
  2. line = "Cats are smarter than dogs"
  3. m = re.match("(.*) are (.*?) .*", line, re.M | re.I)
  4. if m:
  5. print("matchObj.group(0) : ", m.group(0))
  6. print("matchObj.group(1) : ", m.group(1))
  7. print("matchObj.group(2) : ", m.group(2))
  8. else:
  9. print("No match!!")