Re: regular expressions and a text file


Subject: Re: regular expressions and a text file
From: Arthur Corliss (arthur@corlissfamily.org)
Date: Fri Aug 23 2002 - 12:04:17 AKDT


> We have a text file we are trying to parse....each data item is
> separated by a tab...sometimes.
>
> Is there regular expression I can use that would swallow up all of
> the tabs and whitespaces? Will it work in the split command? or
> will I have to process the line first, then hand it to the split command?
>
> For example the data looks like:
>
> data1\t\tdata2\t data3 data4
>
> And the combinations of tabs and spaces is not consistent from line
> to line
> (what a nightmare).
>
> We tried using
>
> split(/\s/,$line);
>
> But this didn't do what we expected...we were hoping the \s would swallow
> all of the whitespace characters.

You need to add a '+' to that to allow to expand for multiple matches (i.e.,
/\s+/).

        --Arthur Corliss
          Bolverk's Lair -- http://arthur.corlissfamily.org/
          Digital Mages -- http://www.digitalmages.com/
          "Live Free or Die, the Only Way to Live" -- NH State Motto

---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.



This archive was generated by hypermail 2a23 : Fri Aug 23 2002 - 12:48:39 AKDT