fork download
  1. import re
  2. s = "These are the words in a sentence"
  3. r = re.compile('(?P<term1>are)|(?P<term2>words)')
  4. print("TERM1:")
  5. print([x["term1"] for x in [m.groupdict() for m in r.finditer(s)]])
  6. print("TERM2:")
  7. print([x["term2"] for x in [m.groupdict() for m in r.finditer(s)]])
  8.  
Success #stdin #stdout 0.01s 8968KB
stdin
Standard input is empty
stdout
TERM1:
['are', None]
TERM2:
[None, 'words']