How to normilize text with regex with some if statements?
If we have string like this
One T933 two, three35.4. four 9,3 8.5 five M2x13 M4.3x2.1
And I want to normilize like this
one t 933 two three 35.4 four 9,3 8.5 five m2x13 m4.3x2.1
- Remove all dots and commas.
- Split number and string if not starts with letter 'M'
T933
-->T 933
- All lowercase
- Do not split if there is dot or comma between numbers
35.4
-->35.4
or9,3
-->9.3
if there is comma between, then replace to dot
What I am able to do is this
def process(str, **kwargs):
str = str.replace(',', '.')
str = re.split(r'(-?\d*\.?\d+)', str)
str = ' '.join(str)
str.lower()
return str
but there is no if condition when numbers starts with letter 'M' and their also is splitted. And in some reason after string process i get some unnecessary spaces.
Is there some ideas how to do that with regex? Or with help methods like replace, lower, join and so on?