0

What would be the correct regex expression for splitting something like '32s' into (32, 's') in Python while also allowing to split something like '31.7435x' into (31.7435, 'x')?

I was using re.findall('(\d+|[A-Za-z]+)', '32s'), but this doesn't allow for floats, whereas '(\d+\.\d+|[A-Za-z]+)' doesn't allow for ints. Trying '(\d+|[A-Za-z]+)|(\d+\.\d+|[A-Za-z]+)' also doesn't work.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1
    `(\d+|\d+\.[\d]*)([A-Za-z]+)` - you were close, but the parentheses `( )` go around the groups you want to capture – bn_ln Oct 09 '22 at 08:00
  • A question being put on hold is something not to mind, as long as (1) you get your answer; (2) the broad point of the question is already represented on Stack Overflow. Does the solution in the above comment work? – halfer Oct 14 '22 at 19:32
  • Yes the solution works. Sorry, not sure what you mean about "A question being put on hold". – crabulus_maximus Oct 15 '22 at 07:37

0 Answers0