[plug] regex

Mark O'Shea mark at musicalstoat.co.uk
Thu Mar 25 14:41:47 WST 2004


On Thu, 25 Mar 2004, David Buddrige wrote:

> Hi all,
>
> I am wanting to write a short regex that will allow me to strip out extra
> spaces between words in an input stream.
>
> The program I have thus far is this:
> #!/usr/bin/perl
>
> while(<>)
> {
>    $_ =~ s/\s{2,10}/ /g;
>    print;
> }
>
> which will replace between 2 and 10 spaces with a single space.  However, I
> want it to be an arbritarily large maximum limit - not simply 10 spaces.
> Does anyone know what I should use as the second parameter between the {}
> braces so that the regex will match 2 or more spaces?  I've been trawling
> through the manuals I have available but so far with no luck.
>
> thanks heaps guys
>
Yup, nothing:
$_ =~ s/\s{2,}/ /g;

will work just fine.

Regards,
-- 
Mark O'Shea



More information about the plug mailing list