in reply to remove spaces only between commas
The first match includes the second comma, so the second match will start at the third one.
Before s///: , , , , , , , 6 After 1st pass: ,,| , , , , , 6 After 2nd pass: ,, ,,| , , , 6 After 3rd pass: ,, ,, ,,| , 6
The | indicates where a substition ended and from where the next pass will search.
Solution 1: Start from the begining instead of where the last match left off.
1 while s{, +,}{,,};
Solution 2: Use a zero-width match to check for the "closing" comma.
s{, +(?=,)}{,}g;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: remove spaces only between commas
by Anonymous Monk on Sep 21, 2007 at 17:37 UTC |