Re: regular expressions, order of evaluation
- From: Phil Carmody <thefatphil_demunged@xxxxxxxxxxx>
- Date: 27 Mar 2007 11:10:24 +0300
"Flo" <sensorflo@xxxxxxxxx> writes:
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?
Your statement is false. Hint - does regex 2 match the empty string?
Phil
--
"Home taping is killing big business profits. We left this side blank
so you can help." -- Dead Kennedys, written upon the B-side of tapes of
/In God We Trust, Inc./.
.
- References:
- regular expressions, order of evaluation
- From: Flo
- regular expressions, order of evaluation
- Prev by Date: Re: make thousands with a 6 dollar investment
- Next by Date: Re: Is this result surprising to you ...
- Previous by thread: Re: regular expressions, order of evaluation
- Next by thread: New mathematics/physical sciences positions at http://jobs.phds.org, March 26, 2007
- Index(es):
Relevant Pages
|