perlquestion
cidaris
I hate to post regex questions, but I'm second-guessing myself every time I think I make progress.<BR><BR>
The problem: I have a CSV file that <a href="http://search.cpan.org/author/ALANCITT/Text-CSV-0.01/CSV.pm">Text::CSV</a>
is handling very nicely.<BR><BR>
Unfortunately, it will balk on data like this:<BR>
"crosby","stills","nash","and sometimes "young""<BR>
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.<BR>
I had tried this, but it's not right:<BR>
<CODE>
if ($line =~ m/".?".?".?"/g)
</CODE><BR>
because it will match the "," that I'm trying to delimit with. My next thought was something like this:<BR>
<CODE>
if ($line =~ m/"[^\,]?"[^\,]?"[^\,]?"/g)
</CODE><BR>
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:<BR>
<CODE>
if ($line =~ m/"(ANY # OF NON-COMMAS)"(ANY # OF NON-COMMAS)"(ANY # OF NON-COMMAS)"/g)
</CODE><BR>
Can anyone who has been through this kind of nightmare help me?<BR><BR>
Thanks,<BR>
cidaris