laxj11
laxj11

Reputation: 117

Regex commas to spaces

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

Upvotes: 1

Views: 184

Answers (2)

Joel Beckham
Joel Beckham

Reputation: 18664

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');

Upvotes: 1

find: ",\s*" (without quotes)

replace with: " " (without quotes, just a single space)

or:

s/,\s*/ /g

Upvotes: 3

Related Questions