fork download
  1. import re
  2.  
  3. import1 = "import first;"
  4. import2 = "import first : f;"
  5. import3 = "import first : f, second : g;"
  6. import4 = "import first, second, third;"
  7.  
  8. p2prime = 'import\s+(?:[a-zA-Z0-9_.]+)\s*(?:(?:\s+:\s+[a-zA-Z0-9_.]+\s*)?(?:,\s*(?:[a-zA-Z0-9_.]+)(?:\s*:\s*[a-zA-Z0-9_.]+)??\s*)*)*;'
  9.  
  10. p2pm1 = re.match(p2prime, import1) # match
  11. if p2pm1 != None:
  12. print "p2prime w/ import1 => " + p2pm1.group(0)
  13.  
  14. p2pm2 = re.match(p2prime, import2) # now a match
  15. if p2pm2 != None:
  16. print "p2prime w/ import2 => " + p2pm2.group(0)
  17.  
  18. p2pm3 = re.match(p2prime, import3) # now a match
  19. if p2pm3 != None:
  20. print "p2prime w/ import3 => " + p2pm3.group(0)
  21.  
  22. p2pm4 = re.match(p2prime, import4) # now a match
  23. if p2pm4 != None:
  24. print "p2prime w/ import4 => " + p2pm4.group(0)
Success #stdin #stdout 0.01s 7692KB
stdin
Standard input is empty
stdout
p2prime w/ import1 => import first;
p2prime w/ import2 => import first : f;
p2prime w/ import3 => import first : f, second : g;
p2prime w/ import4 => import first, second, third;