Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

(MeowChow) Re: Delete unmatched quotes from a delimited file?

by MeowChow (Vicar)
on Jul 24, 2001 at 21:58 UTC ( [id://99430]=note: print w/replies, xml ) Need Help??


in reply to Delete unmatched quotes from a delimited file?

A one-liner regex is not the most maintainable or efficient solution to this problem. But since you asked, here's a regex answer:
  
s/((?:^|\|)(?:[^"|]*"[^"|]*")*[^"|]*)"([^"|]*)(?=$|\|)/$1$2/g;
The readability of that could be improved upon, however:
  
my $T = qr/[^"|]*/; s/((?:^|\|)(?:$T"$T")*$T)"($T)(?=$|\|)/$1$2/go;
Now here's how I would have really done it:
  
join '|', map { s/"([^"]*)$/$1/ if y/"// & 1; $_ } split /\|/;
   MeowChow                                   
               s aamecha.s a..a\u$&owag.print

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-16 23:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found