Split and RegEx Help

From: Vaughn Sargent (sulvand_at_gmail.com)
Date: 08/31/04


Date: 30 Aug 2004 20:28:20 -0700

Hi,

I have some flat file data coming in from a client that is ~
delimited. I have no control over the incoming data so I'm stuck with
the ~. What I need to do is split the data into fields (which should
be easy using split) however, some text fields may contain a ~ but
it's not the delimiter, it's just part of the text field. All text
fields are enclosed with double quotes. Number and date fields are
not. So I may recieve data such as the following 5 field line:

"Field - One"~234.00~"Field ~ 3"~20040830~"Field 5"

What I want returned is:

Field 1: "Field - One"
Field 2: 234.00
Field 3: "Field ~ 3"
Field 4: 20040830
Field 5: "Field 5"

But using split perl returns:

Field 1: "Field - One"
Field 2: 234.00
Field 3: "Field
Field 4: 3"
Field 5: 20040830
Field 6: "Field 5"

It would also be possible for any text field to contain more than one
~ as a non-delimiter which may or may not be next to each other.

I guess what I would like to tell perl is "Hey, Perl, split this line
for me using ~ as the delimiter but ~ isn't a delimiter if there are
double quotes around it."

I thought it might be possible to use split and tack on a regular
expression. I'm a newbie when it comes to regular expressions.

If anyone can help me out I'd be very greatful.

Vaughn



Relevant Pages

  • Re: posix style regexp -> perl style regexp.
    ... Lots of characters that perl ... particular RE to another type of RE, but how to find a proper ... delimiter to use for your Perl code? ... Alternatively, choose a delimiter, and go through your REs to properly ...
    (comp.lang.perl.misc)
  • Re: Learning Perl
    ... EB> Perl with very good results: ... it should be an array, ... used as the delimiter besides ... string1 string2! ...
    (comp.lang.perl.misc)
  • RE: Create HTML code with perl
    ... One reason for the problem is that perl does not recognize ... delimiter to print plain text. ... a pair of double quotes ...
    (perl.beginners)
  • Re: perl 5 grammar
    ... Surprise, surprise. ... The old saying goes "only perl can parse Perl". ... characters identifying a string but there ...
    (comp.lang.perl.misc)
  • Re: INSERT Query problem with Quotes & Apostrophes
    ... something like that whereby Access does this for you, as the double quotes ... > delimiter symbol in your string. ... If your user has the Short Date format set to ...
    (microsoft.public.access.modulesdaovba)