fork download
  1. import re
  2.  
  3. regex = r"(NP_\w+)(?: \([^()]+\))? is (NP_\w+)"
  4. test_str = "NP_The_Eleventh_Air_Force is NP_a_Numbered_Air_Force of NP_the_United_States_Air_Force_Pacific_Air_Forces (NP_PACAF)."
  5. matches = re.search(regex, test_str)
  6.  
  7. if matches:
  8. print(matches.group(1))
  9. print(matches.group(2))
Success #stdin #stdout 0.02s 9580KB
stdin
Standard input is empty
stdout
NP_The_Eleventh_Air_Force
NP_a_Numbered_Air_Force