Re: idiom for iterating

Bill Yerazunis <[email protected]> Wed, 22 Apr 2009 15:05:09 -0400
Newsgroups gmane.mail.spam.crm114
Message-ID <[email protected]>
   From: Thomas Michael Hagen <[email protected]>

   normally, you would use the keyword <fromend> to iterate over matches
   in a file. this works when the pattern is simple, like
   /(what-you-want)(something-else)/.

   however, when you are looking for something that looks like this:
   /(start-tag)(you-want-this)(next-start-tag)/, the <fromend> keyword
   will cause you to only match every second instance. the <fromnext>
   keyword will cause you to match every instance but the first.

Hmmm...  interesting point.  (I'm CCing Ville Laurikari on this because
he's the absolute guru and author of the TRE engine we use)

How about using a bracket negation chain in the regex?  This will give
you cleaner code (but a harder to understand regex).

The charset negation chain regex would look like something like this
( DANGER - UNTESTED REGEX!) :

   /(#http:.?CET .....)(([^#]|#[^h]|#h[^t]|#ht[^t]|#htt[^p]|#http[^:])*)/

bracket negation chain:  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The idea of that long negated string is to match the longest 
string of anything that does NOT start with #http: by reduction:

  either it does not start with "#", else
  it starts with "#" but does not have "h" as the next character, else
  it starts with "#h" but does not have "t" as the next character, else
  it starts with "#ht" but does not have "t" as the next character, else
  it starts with "#htt" but does not have "p" as the next character, else
  it starts with "#http" but does not have ":" as the next character

Anyway, this might work for you.  It might also be a lot slower
than your "clumsy hack"... only testing on your actual data will
tell for sure.

Yes, I'd love a more compact way to express this, but I know of
none.  I wonder if this is a good opportunity to extend the REGEX language?
I'm not quite sure what the syntax should be, mind you.  Maybe
we can hang it off of the .*? syntax as "and also this must be
true"

Ville: what do you think?

     - Bill Yerazunis  

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p