Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

by MeowChow (Vicar)
on Jul 24, 2001 at 21:58 UTC ( #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? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2022-01-28 09:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (73 votes). Check out past polls.

    Notices?