fork download
  1. import re
  2.  
  3. testWords = ["(1) 教育類", "(2) 科學類", "(3) 語言類"]
  4.  
  5. pat = re.compile(r"\(\d\)\W(?P<type>.+)")
  6.  
  7. for w in testWords:
  8. m = pat.search(w)
  9. print(m.group("type"))
Success #stdin #stdout 0.03s 9580KB
stdin
Standard input is empty
stdout
教育類
科學類
語言類