fork download
  1. import re
  2.  
  3. pattern = r'\b([A-Z]{2,4})\s(4000|[1-3][0-9]{3}):\s("[a-zA-Z]+(?:\s[a-zA-Z]+)*")'
  4.  
  5. s = ("CS 1110: \"Introduction to Programming\", ENGR 1624: \"Introduction to\n"
  6. "Engineering\", and BME 2220: \"Biomechanics\"\n\n"
  7. "CS 20: \"Introduction to CS\", ENGR 1624: \" \", and ENGR 1624: \"\"")
  8.  
  9. print(re.findall(pattern, s))
Success #stdin #stdout 0.02s 9624KB
stdin
Standard input is empty
stdout
[('CS', '1110', '"Introduction to Programming"'), ('ENGR', '1624', '"Introduction to\nEngineering"'), ('BME', '2220', '"Biomechanics"')]