-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
  • 668
  • 1
  • 7
  • 23
Philippe
  • 14,211
  • 2
  • 16
  • 22

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
  • 330,695
  • 80
  • 606
  • 657