i need a regex that converts commas to spaces. I know this is super simple, but i do not know regex. thanks.
tag1, tag2, tag3, tag4,tag5 tag6
to
tag1 tag2 tag3 tag4 tag5 tag6
thanks
i need a regex that converts commas to spaces. I know this is super simple, but i do not know regex. thanks.
tag1, tag2, tag3, tag4,tag5 tag6
to
tag1 tag2 tag3 tag4 tag5 tag6
thanks
find: ",\s*"
(without quotes)
replace with: " "
(without quotes, just a single space)
or:
s/,\s*/ /g
Yuku's got it right. Here's in context:
preg_replace('/,\s*/', ' ', 'tag1, tag2, tag3, tag4,tag5 tag6');
If some of your tags without commas between them have more than one space, you could use this instead:
preg_replace('/,\s*|\s+/', ' ', 'tag1, tag2, tag3, tag4,tag5 tag6');