Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: regex match in list context

by flounder99 (Friar)
on Oct 02, 2003 at 19:07 UTC ( [id://296033]=note: print w/replies, xml ) Need Help??


in reply to regex match in list context

What happened is that once it failed on "" it just skipped the first quote and moved on to the next character which was the closing quote so it matched on "," and continued from there. There are several ways to do what you want. Some are simple if you don't have to worry about embeded escaped quotes some thing like
/("[^"]*?")/g
Would work.
If you have embeded escaped quotes you can use this:
/("(?:\\"|[^"])*?")/g
like this
my $mm=qq(\"000.E+3\",\"\",\"\",\"\",\"QCA-086_2\",\"-1\",\"P\",\"FALS +E\",\"this \\\"is\\\" quoted\"); my @p = ($mm=~m/("(?:\\"|[^"])*?")/g); print $mm, "\n", map {qq($_\n)} @p; __OUTPUT__ "000.E+3","","","","QCA-086_2","-1","P","FALSE","this \"is\" quoted" "000.E+3" "" "" "" "QCA-086_2" "-1" "P" "FALSE" "this \"is\" quoted"
There are several modules that you can use like Text::Balanced and Regexp::Common

--

flounder

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://296033]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-19 07:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found