Reputation: 5969
I tried this:
echo preg_replace('/[^,,$]/', '', ',test,hi,');
But gets:
,,,
Upvotes: 0
Views: 1177
Reputation: 212522
preg_replace is a bit overkill
$string = ',,ABCD,EFG,,,,';
$newString trim($string,',');
Upvotes: 4
Reputation: 523684
Do you mean
preg_replace('/^,|,$/', '', ',test,hi,');
? Inside a character class […]
, a leading ^
means negation, and $
doesn't have any special meanings.
You could use the trim
function instead.
trim(',test,hi,', ',');
Upvotes: 7