Re: regular expressions, order of evaluation



"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./.
.



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)
  • 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 ...
    (comp.lang.perl.misc)
  • Re: [opensuse] regexp -- defference between < and  ?
    ... Randall R Schulz wrote: ... With regular expressions, what is the difference between \< and \b? ... There are many grammars for notating them and many varieties of fundamental matching constructs. ... The symbols \respectively match the empty string at the beginning and end of a word. ...
    (SuSE)
  • Re: Find instance in a string
    ... If there is no 4 character number in the input, an empty string is returned ... The following sites provide a wealth of information on regular expressions. ...
    (microsoft.public.dotnet.languages.vb)
  • [opensuse] regexp -- defference between < and  ?
    ... With regular expressions, what is the difference between \< and \b? ... "The symbols \respectively match the empty string at the beginning and end of a word. ... Nacogdoches, Texas 75961 ...
    (SuSE)