Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Regular Expression

Reply
Thread Tools

Regular Expression

 
 
Ray
Guest
Posts: n/a
 
      08-31-2003
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?


 
Reply With Quote
 
 
 
 
George Karabotsos
Guest
Posts: n/a
 
      08-31-2003
"Ray" <(E-Mail Removed)> wrote in message
news:SRc4b.1290$(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
 
Ray
Guest
Posts: n/a
 
      08-31-2003
George Karabotsos wrote:

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


Thanks, it's working now.







 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seek xpath expression where an attribute name is a regular expression GIMME XML 3 12-29-2008 03:11 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
Matching abitrary expression in a regular expression =?iso-8859-1?B?bW9vcJk=?= Java 8 12-02-2005 12:51 AM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments