On Aug 14, 6:28 am, [email protected] ("C.DeRykus") wrote:
> On Aug 13, 1:47 pm, [email protected] (irata) wrote:
>
>
>
>
>
> > I want to replace in a javscript structure like the one below every
> > occurence of "{#...}", "{?...}", "{+...}" and "{=...}" through
> > something different (also nested):
> >    function() {
> >       test1 = "{#Caption}";
> >       test2 = "{#Te{?st}}";
> >       test3 = "{+date.{0}}";
> >    }
>
> > with this regular expression
> >   my( $open )   = qr/{[=+#?]/;
> >   my( $close )  = qr/}/;
> >   my( $not )    = qr/[^{}]++/;
> >   do {
> >      $found = $text =~ s/
> >       (
> >         $open
> >         (?: $not | (?1) )
> >         $close
> >       )
> >      /replace($1)/esxg;
> >   } while ( $found );
> > I can handle case "test1" and "test2" but the case "test3" won't work.
> > Could some help me how I can change the expression that it match
> > "{+date.{0}}" without bothering about the "{0}" (this could also be
> > "{foo}").
>
> > I try it with:
> >   my( $not ) = qr/(?>(?:(?!$open)|(?!$close))+)/;
> > but that won't work.
>
> [Your question would probably be better posted in
>     comp.lang.perl.misc]
>
> One good debugging technique to track what the regex
> engine is doing:   use re 'debug'
>
> I believe the problem is that once the inner {0} is found
> the recursion pattern fails because $open is  {[=+#?] and
> {0} won't match.
>
> You could perhaps make it work by checking whether
> you're recursing to alter the pattern accordingly:
>
> untested tweak:
>
> my( $open )   = qr/ (? (R) [=+#?] | [=+#?]? ) /x;
>

Good thing I wrote "untested".

Make that tweak:

my( $open )   = qr/{(? (R) [=+#?] | [=+#?]?)/;

--
Charles DeRykus


--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to