in reply to Help with Substitution

I tested your original code, and got results different than what you report:

> {john{david{mary{empty{{empty{martin}

This is the result my test got, and what I would expect (correct behavior) from that regex code. If you really want ALL double { out, then the lookahead code suggested above would seem to be the optimal way.

TbR

Replies are listed 'Best First'.
Re: Re: Help with Substitution
by John M. Dlugosz (Monsignor) on Jun 29, 2001 at 18:26 UTC
    OK, I give up: why does the expression only replace the {{ once?

      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.