in reply to Re: Help with Substitution
in thread Help with Substitution

OK, I give up: why does the expression only replace the {{ once?

Replies are listed 'Best First'.
Re: Re: Re: Help with Substitution
by tye (Sage) on Jun 29, 2001 at 19:49 UTC

    Because the regex starts where it left off and it already matched the first two characters of "{{{" to become "{empty{{" so it starts looking at the third "{" and, from there, never finds "{{".

    *{john{david{mary{{{martin} ^ Start there looking for {{ or {} {john{david{mary*{{{martin} ^ stop here, having found a match {john{david{mary{empty{*{martin} ^ resume here no {} nor {{ left to find from there

    Update: Unless you are asking why it would only match once against "{{{{", in which case the answer is "it doesn't; it matches twice".

            - tye (but my friends call me "Tye")
      Yea (about the update), I thought he said that /\{\{/g only matched "{{{{" once.