• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Need help with simple regex pattern matching

I need to match a comma and any number of spaces and replace it with one space. The closest I can come up with is [,\s*] but its not interpreting correctly. Where am I going wrong?
 
if you used [,\s*] literally (including []) as your expression then you defined a class of characters to match, not a sequence. Basically regex will check for anything matching in the set regardless of order. You can define a group, or sequence, by using () instead or nothing at all as esun shows.

So, [,\s*] will match a single comma or single space (not entirely sure what the * will do in this context and I'm too lazy to look it up). (,\s*) will match a comma followed by zero or more spaces greedily.
 
Ohh, yeah, Onund is right. If you write [,\s*], it will match a comma, any whitespace character, and any asterisk, which is not what you want.
 
Originally posted by: esun
Ohh, yeah, Onund is right. If you write [,\s*], it will match a comma, any whitespace character, and any asterisk, which is not what you want.

😕

Please reread what Onund posted.
 
Originally posted by: tfinch2
Originally posted by: esun
Ohh, yeah, Onund is right. If you write [,\s*], it will match a comma, any whitespace character, and any asterisk, which is not what you want.

😕

Please reread what Onund posted.

I did. Aside from the asterisk part, he was right (and he wasn't technically wrong about that, since he said he didn't know). Now what was your point?
 
Back
Top