order of evaluation



Hello

Consider these two regular expressions
1) .*.*
2) .*?.*?

which are equivalent to
1) (.*)(.*)
2) (.*?)(.*?)

Where the * is the greedy 0-or-more quantifier and *? the lazy 0-or-
more quantifier. In the following \1 is a backreference to the match
inside the first parenthesis, \2 likewise for the 2nd parenthesis.

As I understand it, most flavours of regular expressions have the
following behaviour for the two regexes above
1) \1 returns the whole target string, \2 returns the empty string
2) \1 returns the empty string, \1 returns the whole target string

Is that statement correct at all, i.e. do indeed most flavours have
that behaviour?

Which rules dictates that behaviour? I would say
"for regexes, order of evaluation is left to right"
But I am not sure since I never saw such a statement.

Remember that "order of evaluation" and "precedence" are *not* the
same thing, at least not in general. See also
http://groups.google.com/group/comp.lang.c/browse_thread/thread/5bc23...

Flo

.



Relevant Pages

  • regular expressions, order of evaluation
    ... inside the first parenthesis, \2 likewise for the 2nd parenthesis. ... most flavours of regular expressions have the ... \1 returns the whole target string, ... Is that statement correct at all, i.e. do indeed most flavours have ...
    (sci.math)
  • Re: regular expressions, order of evaluation
    ... inside the first parenthesis, \2 likewise for the 2nd parenthesis. ... most flavours of regular expressions have the ... \1 returns the whole target string, \2 returns the empty string ... Is that statement correct at all, i.e. do indeed most flavours have ...
    (sci.math)
  • Re: Efficient regular expression pattern ?
    ... I'm thinkg about a "IUrlFilter": ... Regular expressions are a generic system of pattern matching that uses a ... for the fact that it is generic and the fact that patterns are ... you have a small number of patterns and a single long target string or ...
    (microsoft.public.dotnet.framework)