I can think of "foreach string replace" ways of doing this but feel that a regex replace method would be faster and more elegant, unfortunately regex is not my strongest thing.
I want to take a string like this
23 AB 5400 DE 68 RG
and turn it into
23AB 5400DE 68RG
The number of spaces between the digits and following letters is USUALLY one but could be variable.
I have this example, that is working to find the groups but how do I get rid of the spaces in the replacement?
https://regex101.com/r/ODhpQM/2
This is the code generated by my attempt
$re = '/(\d+ +)(AB|DE|RG|DU)/m';
$str = '23 AB 5400 DE 68 RG
33 DU 88 DE 8723 AB
55 RG 76 AB 92 DE';
$subst = '\\1\\2';
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;