I have a string
81.5r3
I need to create a regex pattern, So that I should get a exact list as mentioned below
['81.5', 'r', '3']
The pattern should be float, char, int
Is there any way to achieve this?
Try something like regex101.com for quick experimentation?
For a "float, char, int" sequence, it'll be something like:
(-?[0-9]+(?:\.[0-9]+)?)(.)(-?[0-9]+)
You can refine it if you want to do things like forbid leading/trailing zeros:
(-?[1-9][0-9]*(?:\.[0-9]*[1-9])?)(.)(-?[1-9][0-9]*)
You may also need to refine it if you need to support exponential notation (1.2e3) or NaN/Inf values for the float part.
(\d+[.]\d)([a-z])(\d)
I made a simple regex. I think that's enough for you to upgrade it, good luck, and happy new year.
Please check
https://regex101.com/r/kFYzag/5
Please use regex101 to try your idea.
re.split(r"([a-z])", '81.5r3')
You can use re.split using a capture group to get what you want.
The output would be ['81.5', 'r', '3']
(81\.5)(r)(3)