On Sat, Dec 19, 2009 at 9:13 PM, sftriman <dal...@gmail.com> wrote:

> I use this series of regexp all over the place to clean up lines of
> text:
>
> $x=~s/^\s+//g;
> $x=~s/\s+$//g;
> $x=~s/\s+/ /g;
>
> in that order, and note the final one replace \s+ with a single space.
>
> Basically, it's (1) remove all leading space, (2) remove all trailing
> space,
> and (3) replace all multi-space with a single space [which, at this
> point,
> should only occur on interior characters].
>

Take a look at the String::Util module. The "crunch" function, for example,
also removes leading/trailing/multiple spaces.

-- 
Robert Wohlfarth

Reply via email to