fork download
  1. import re
  2. r = r"These\s+are\s+my\s+variables((?:\s*-\w+\s+\$\w+)*)\s+for\s+(case\d)"
  3. s = "These are my variables -abc $def -geh $ijk for case1"
  4. m = re.search(r, s)
  5. if m:
  6. print(re.findall(r'-(\w+)', m.group(1)))
  7. print(re.findall(r'\$(\w+)', m.group(1)))
  8. print(m.group(2))
Success #stdin #stdout 0.02s 9016KB
stdin
Standard input is empty
stdout
['abc', 'geh']
['def', 'ijk']
case1