Re: Right Associative Matching Example (for Docs)
Chris Babcock <[email protected]>
| Newsgroups | gmane.mail.spam.crm114 |
|---|---|
| Organization | ASCII King Games |
| Message-ID | <[email protected]> |
On Thu, 18 Dec 2008 15:02:47 +0100 Paolo <[email protected]> wrote: > On Thu, Dec 18, 2008 at 04:15:55AM -0700, Chris Babcock wrote: > > Use right associative matching when working with tabular data and > > you want to match columns near the end of the line. For example, > > parsing a CSV file with /(?i:":*:email:".+?"([[:print:]]+?)".+?\n)/ > > matches the column after :email: > > while /(?ir:":*:email:".+?"([[:print:]]+?)".+?\n)/ matches the last > > column on the line. > > what's the wanted result here? I get: > > $ cat /tmp/csv.csv > "1","a","[email protected]","uno","due","tre" > "2","b","[email protected]","uno","due","tre" > "3","c","[email protected]","uno","due","tre" > > $ crm '-{isolate (:e:) /[email protected]/ > match (:: :a:) /(?ir:":*:e:".+?"([[:print:]]+?)".+?\n)/ > output /a=:*:a:\n/ > }' < /tmp/csv.csv > a=, > > $ crm '-{isolate (:e:) /[email protected]/ > match (:: :a:) /(?i:":*:e:".+?"([[:print:]]+?)".+?\n)/ > output /a=:*:a:\n/ > }' < /tmp/csv.csv > a=, > > not very meaningful to me. Try: crm '-{isolate (:e:) /[email protected]/ match (:: :a:) /(?ir:":*:e:".+?"([[:print:]]+?)".*?\n)/ output /a=:*:a:\n/ }' < /tmp/csv.csv The problem is that I was overcompensating for a bad habit. I've been trying to break the habit of using * when I mean +. If you don't have a comma or some other character at the end of the line then the closing quotes go to satisfy the ".+?" and the comma becomes the last 'field'. Chris ------------------------------------------------------------------------------ SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada. The future of the web can't happen without you. Join us at MIX09 to help pave the way to the Next Web now. Learn more and register at http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/