Page 1 of 1

Stripping redundant whitespace -- whats wrong?

Posted: Wed Jul 08, 2009 1:59 pm
by alex.barylski
I have the following code:

Code: Select all

$value = 't    -   his     is a spaced line';
$value = preg_replace('#\s{2,}+#', ' ', $value);
All whitespace *except* that right at the start is being replaced with a single space why is the first not as well?

Re: Stripping redundant whitespace -- whats wrong?

Posted: Wed Jul 08, 2009 11:21 pm
by ridgerunner
There isn't anything worng with your regex. I just copied and pasted your code into a php script and it works A-Ok. Also checks out in RegexBuddy.