Why does this no replace all commas with @ except the one in ‘location, state’?
$test = preg_replace("#([^ ])([,])([^ ])#","$1@$3","100,,,'test','two',,'location, state',,[],1")
Expected: 100@@@’test’@’two’@@’location, state’@@[]@1
Actual: 100@,,’test’@’two’@,’location, state’@,[]@1
I think it is because the consecutive commas are matched in the pattern, how do i get it to continue from the start of the matched character to include all commas?
Use this one: