-1

I can get numeric with this:

>>> import re
>>> re.findall(r'\d+', '!"123%&654()')
['123', '654']

How can I get all the components ?

['!"', '123', '%&', '654', '()']
Akshat Zala
  • 710
  • 1
  • 8
  • 23
Philippe
  • 20,025
  • 2
  • 23
  • 32

1 Answers1

0

For reference, with findall, you would greedily look for only digits, or only non-digits:

re.findall(r'\d+|\D+', '!"123%&654()')
# ['!"', '123', '%&', '654', '()']

split is a little cleaner.

cs95
  • 379,657
  • 97
  • 704
  • 746