Page 1 of 1

A question of spaces ...

Posted: Sun Jun 24, 2007 1:39 pm
by contiw
A string contains just one comma.
The comma must be followed by one space.
I need to eliminate any combination of leading and trailing spaces around that comma only, then add the required space after it.

Please advice how to do it wit RegEx.
ThankYou have a nice weekend.

Posted: Sun Jun 24, 2007 2:02 pm
by Benjamin

Code: Select all

preg_replace('#\s{0,},\s{0,}#', ', ', $string);

Posted: Sun Jun 24, 2007 2:34 pm
by contiw
Thank You Astions. Much appreciate and learning.
ContiW

Posted: Sun Jun 24, 2007 4:31 pm
by stereofrog
"*" is a more common way to express "{0,}"

Posted: Sun Jun 24, 2007 4:34 pm
by Benjamin
I like to be verbose.

Posted: Sun Jun 24, 2007 5:09 pm
by superdezign
astions wrote:I like to be verbose.
Yeah, that's a good way to teach. You know, assuming they know how the {} quantifier works. If they do, then giving both examples would clear up any misconception they have about the asterisk, considering it's so overused.

Edit: I didn't mean overused in the sense of being used too much. It *is* a necessity. :D