I want to replace any space in $string
with an underline
but NOT if the space is surrounded by [a-z]
$string = '@@ @@ English something else';
I tried this but it replaces "@@ @@" to "@_@"
$string = preg_replace('/[^a-z]\s[^a-z]/ui', '_' , $string);
I want the output to look like this
@@_@@_English something else
sorry i don't know how to use code in comment, so just add a reply
tested the 2nd and 3rd pattern also work
i understand the 2nd one, but the 3rd one a bit hard for me LOL
i need to go check https://www.regular-expressions.info/
$string = '英文名 中文名 Peter Wong,John Tam,Sam Hu';
$string = preg_replace('/(?<![a-z]) | (?![a-z])/i', ',', $string);
output is
英文名,中文名,Peter Wong,John Tam,Sam Hu
because CJK Name is no space between each char, so this solved the big problem for me
worked like a charm ;)
Thankyou @mickmackusa