From: Charles Hixson Date: 2004-09-20T06:13:35+09:00 Subject: Re: Method improvement request .-- David A. Black wrote: >Hi -- > >On Sun, 19 Sep 2004, Charles Hixson wrote: > > > >>That's a very interesting rewrite of the parse1 match patterns. >>It's a bit more complicated than that, e.g., at the match boundary >>apostrophe's aren't a part of the middle, but in the middle (of the >>middle) they are. Think about 'don't'. >> >> >Think about "'tis" :-) > > OUCH! An excellent point. I don't know how to handle that except by another special case pre-processor. Sigh! I was *SO* hoping to minimize special cases. (Of course, I knew that would be impossible, but still...) >>P.S.: Does scan keep recycling ...it with (an elaboration of) >>chunks = line.scan(/^((\W*)(\w*)(/W*)s+/)$).flatten >> >> >scan keeps recycling its pattern, but note that ^ and $ will be >included each time. Note also that ^ and $ apply to lines, not the >entire string. Thus: > > $ ruby -e 'p "a\nb\ncde\n".scan(/./)' > ["a", "b", "c", "d", "e"] > $ ruby -e 'p "a\nb\ncde\n".scan(/^.$/)' > ["a", "b"] > >You can use \A and \Z to indicate start and end of string (or \z to >match end-except-for-possible-newline). >David > Mmmph... This may take a bit of experimentation to get right. OTOH, \z could save a chomp invocation on each line. (I do think that handling a line at a time is the appropriate choice. The other reasonable choice would be to accumulate text until I encounter a blank line, and then parsing it all in one go. But that's a bit more sensitive to the formatting of the text, and could result in excessively large buffers. (You can certainly tell I'm no expert at regexps.)