Woodhouse, Mike (ANTS) wrote:

>Typing straight from Mr Friedl, this is the java.util.regex version for
>CSV...
>
>Pattern pCSVMain = Pattern.compile(
>"\\G(?:^|,)                                          \n"+
>"(?:                                                 \n"+
>"    # Either a double-quoted field...               \n"+
>"    \" #field's opening quote                       \n"+
>"        (  (?> [^\"]*+ ) (?> \"\" [^\"]*+ ) *+ )    \n"+
>"    \" # field's closing quote                      \n"+
>"    # ... or ...                                    \n"+
>"    |                                               \n"+
>"        # ... some non-quote/non-comma text ...     \n"+
>"       ( [^\",]*+ )                                 \n"+
>")                                                   \n",
>Pattern.COMMENTS);
>  
>
Thanks.

Whew!  I remember reading the (probably perl) equivalent of that when I 
made my first pass through the book, but had forgotten how tricky it was 
:-).

Thanks for that.  I'll give it a go when I get to work this morning.

>I hope I haven't made any transcription errors; I'm not very
>Java-literate...
>
Not to worry, I'll hunt out my copy of the book over the weekend (it's 
in one of the many boxes of books in the garage since my last move).

>While I love the book, I sometimes think some kind of "Regexp Cookbook"
>might be a big timesaver as I hunt for the thing I need, not being enough of
>a regular Regexp user or having enough brainpower to keep stuff in my head.
>
Yes, regexes are a classic case where a cookbook would probably be 
invaluable.  I must admit, though, that generally I can get a regex for 
most things with minimal effort.  It's just when you have things like 
this where the alternative is splitting the problem into a bunch of 
regexes that having a recipe like that would be very very handy.

Cheers,

Harry O.