I am trying to add whitespace before the first letter in a string using Regex. For example if I had a string of "0.5g" I would like the string to become "0.5 g".
I have tried to run a regex query that adds a space after a number, but this causes me problems when it has a decimal point between.
My current regex is
'135mg'.replace(/(\d)([^\d\s%])/g, '$1 $2'); // Returns 135 mg as expected
'0.5g'.replace(/(\d)([^\d\s%])/g, '$1 $2'); // Returns 0. 5 g which is wrong as there is a whitespace before 5
Thanks