[plug] regex

Ryan ryan at is.as.geeky.as
Thu Mar 25 14:47:09 WST 2004


On Thu, 2004-03-25 at 14:36, 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. 
> 

{2,}  <-  will do 2 or more

Ryan





More information about the plug mailing list