I wish to turn this string:
"25 Horse Power" to "25Horse Power"
And respectively
"Foo bar 25 stack 1 overflow" to "Foo bar 25stack 1overflow"
Is there an efficient way of doing this in regex?
Using lookarounds regex:
$repl = preg_replace('/(?<=\d)\h+(?=[a-zA-Z])/', '', $input);
(?<=\d) # assert that previous char is a digit
\h+ # match 1 or more horizontal space
(?=[a-zA-Z]) # assert that next char in an English letter