On Nov 28, Michael Fowler said: > $_ = "I want to delete all this spaces, but this"; > s/(^|[^ ]) ([^ ]|$)/$1$2/g; > >It seems there should be a simpler way, perhaps without the $1 $2 >replacement, but that's the best I came up with.
My look-behind/ahead approach does, but I don't think it's an optimal approach: s/(?<!\s)\s(?!\s)//g; But that's slow. I suggest s/(\s+)/length($1) > 1 and $1/eg; That says: if the length of $1 is greater than 1, replace it with itself, otherwise, replace it with nothing. (The X > Y returns '', not 0, for false.) -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]