fork download
  1. import re
  2.  
  3. def f1(data):
  4. p = re.compile('(?P<dept>[A-Z]{2,3}) (?P<num>[0-9]{3})')
  5. return p.search(data)
  6.  
  7. obj = f1('CS 101')
  8. dept, num = obj.group('dept'), obj.group('num')
  9.  
  10. print dept
  11. print num
Success #stdin #stdout 0.02s 7216KB
stdin
Standard input is empty
stdout
CS
101