Boost logo

Boost Users :

From: Detlef Meyer-Eltz (Meyer-Eltz_at_[hidden])
Date: 2006-12-18 12:05:18


I have a difficulty to predict, which part of a regular expression
will match.

Example:
I have a regular expression for a general HTML tag: <[^>]*>
combined with an expression for the body tag: <body([^>]*)>

to: (<[^>]*>)|(<body([^>]*)>)

This expression matches the text: <body bgcolor="white">

As both alternatives can match the input with the same length, I
expected, that the repeated fouth part of the "Leftmost Longest" Rule
would determine, which alternatve is chosen:

4. Find the match which has matched the first sub-expression in the
   leftmost position, along with any ties. If there is only on(e)
   such match possible then return it.

// note the missing 'e'

As the tag-expression has no sub-expression at all, the
body-expression should win. Its sub-expression could match, but
doesn't. It seems to me, that the sequence of the alternatives
determines the match.

Now I guess, that I misinterpreted 4.: its not a means to predict the
matching alternative but only to find the one that matched
accidentally? My software constructs lexers from elementary
expressions automatically. So it's important for me to direct and
predict the expected matching alternative. Are there any other rules?
Does the sequence of the alternatives determine the match
unmistakably?

With Kind Regards,

Detlef Meyer-Eltz


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net