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 08:04:19 -0500
Bill Yerazunis <[email protected]> wrote:

> 
>    From: Chris Babcock <[email protected]>
> 
>    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. 
> 
> Excellent example.
> 
> Can you give me example text that you'd see in the .csv?
> 
>     - Bill Yerazunis

...
...,"[email protected]","address1","address2",..."others","phone",
...

/(?i:":*:email:".+?"([[:print:]]+?)".*?\n)/ matches address1
/(?ir:":*:email:".+?"([[:print:]]+?)".*?\n)/ matches phone

(Use * instead of + since you cannot sure of a trailing comma.)

For CSV some variation of this idiom would work:
/(?in:":*:email:".+"([[:print:]]+?)".+?)/ matches phone

This is especially nice for parsing tables where the record is not line
delineated (like HTML).

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/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.