I hate to post regex questions, but I'm second-guessing myself every time I think I make progress.

The problem: I have a CSV file that Text::CSV is handling very nicely.

Unfortunately, it will balk on data like this:
"crosby","stills","nash","and sometimes "young""
The input can include any number of characters, and unfortunately, I don't have control over the input to tell people "hey, don't use anything but letters or numbers!" Believe you me, I'd love to put some constraints on their input, but it's a proprietary tool, and, well, I could lecture until I was blue in the face and some snot-nosed kid would immediately enter every non-alphanumeric character he could find.
I had tried this, but it's not right:
if ($line =~ m/".?".?".?"/g)

because it will match the "," that I'm trying to delimit with. My next thought was something like this:
if ($line =~ m/"[^\,]?"[^\,]?"[^\,]?"/g)

but that would only work if a comma were a class of character... And probably not even then ;) I guess in pseudo-code, I'm after something like this:
if ($line =~ m/"(ANY # OF NON-COMMAS)"(ANY # OF NON-COMMAS)"(ANY # OF +NON-COMMAS)"/g)

Can anyone who has been through this kind of nightmare help me?

Thanks,
cidaris

In reply to CSV and regex mixups by cidaris

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.