I have a string that is not properly formed and am attempting to correct it. An example of the string is: -
A Someone(US)B Nobody(US)
I am attempting to correct it to: -
A Someone(US) B Nobody(US)
I am using the below code to match ")" followed by a capital letter and using php's preg_replace function to do the match and add the space. However I'm completely rubbish at regex and cannot get the space added in the correct place.
$regex = "([\)][A-Z])";
$replacement = ") $0";
$str = preg_replace($regex, $replacement, $output);
Can anyone suggest a better method? I realise the space is not adding correclty because $0 contains the data I am matching, is there a way to manipulate $0?
([\)][A-Z]), just move the paranthesis like this[\)]([A-Z])and use $1 I think.