fork download
  1. import re
  2. stuff = ["$x$y0123", "$", "", " \t", "$x @hi"]
  3.  
  4. p1 = re.compile(r'(?:\$[A-Z_]\w*|\s)*$', re.IGNORECASE)
  5. p2 = re.compile(r'\$[A-Z_]\w*|\s+', re.IGNORECASE)
  6.  
  7. for thing in stuff:
  8. if p1.match(thing):
  9. print(p2.findall(thing))
  10.  
Success #stdin #stdout 0.01s 7852KB
stdin
Standard input is empty
stdout
['$x', '$y0123']
[]
['  \t']