Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl (http://www.velocityreviews.com/forums/f17-perl.html)
-   -   Regular Expression (http://www.velocityreviews.com/forums/t24337-regular-expression.html)

Ray 08-31-2003 02:16 AM

Regular Expression
 
I'm working on a Perl script that reads a text file. The file could have
multiple new lines together, could have lots of spaces between words, tabs,
and so on. Bottome line, I want to end up with the text from the file all
in a single line, with nothing but single spaces between words.

So my Perl script reads the file into an array and puts the lines together
with join. That much is good. From what modest amount I know about regular
expressions, I'd expect to be able to get the extra spaces out this way:

$text =~ s/\s+/ /g;

....but I seem to be wrong to expect that.

How can I get what I want?



George Karabotsos 08-31-2003 02:48 PM

Re: Regular Expression
 
"Ray" <wonderfulray@yahoo.com> wrote in message
news:SRc4b.1290$L6.895@bignews6.bellsouth.net...
> I'm working on a Perl script that reads a text file. The file could have
> multiple new lines together, could have lots of spaces between words,

tabs,
> and so on. Bottome line, I want to end up with the text from the file all
> in a single line, with nothing but single spaces between words.
>
> So my Perl script reads the file into an array and puts the lines together
> with join. That much is good. From what modest amount I know about regular
> expressions, I'd expect to be able to get the extra spaces out this way:
>
> $text =~ s/\s+/ /g;
>
> ...but I seem to be wrong to expect that.
>
> How can I get what I want?
>
>


This should work:
$text =~ s/\s+/ /gm;

George



Ray 08-31-2003 04:18 PM

Re: Regular Expression
 
George Karabotsos wrote:

> This should work:
> $text =~ s/\s+/ /gm;


Thanks, it's working now.









All times are GMT. The time now is 02:26 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.