fork download
  1. import re
  2.  
  3. xs = [
  4. re.search(r"[0-9]+", "abc123def45gh987zy").group(0),
  5. re.findall(r"[0-9]+", "abc123def45gh987zy"),
  6. re.findall(r"[fb]ar", "foo bar baz far faz"),
  7. re.findall(r"((foo).*(bar))", "fofoofabarba"),
  8. re.match(r"bar", "foobar"),
  9. re.match(r".*bar", "foobar").group(0),
  10. ]
  11. print(*xs, sep='\n')
  12.  
  13. license = "ABC-123"
  14. full, lpart, npart = re.match(r"((\w\w\w)-(\d\d\d))", license).groups()
  15. print("The plate", full, "has number part", npart)
Success #stdin #stdout 0.1s 10104KB
stdin
Standard input is empty
stdout
123
['123', '45', '987']
['bar', 'far']
[('foofabar', 'foo', 'bar')]
None
foobar
The plate ABC-123 has number part 123