order of evaluation
- From: "Flo" <sensorflo@xxxxxxxxx>
- Date: 26 Mar 2007 03:41:21 -0700
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
.
- Follow-Ups:
- Re: order of evaluation
- From: Flo
- Re: order of evaluation
- Prev by Date: nomenclature
- Next by Date: Re: order of evaluation
- Previous by thread: nomenclature
- Next by thread: Re: order of evaluation
- Index(es):
Relevant Pages
|