[Seaside] [FIX] liverUpdate JavaScript problem

Pennell, David DPennell at quallaby.com
Fri Jan 7 20:22:19 CET 2005


> > > That's a lot more than I expected too.  The intent was to go from
the
> > > first open tag with an id to the last close tag for the same
element.
> > > I think the problem is in the ".*?id" - it should be something
like
> > > [^>]*?id so that it can't cross tags.
> >
> > Yes - I tried that version and it works, but ends up being more
> > restrictive in that it will stop at the first close tag that matches
the
> > one with the id.
> 
> Hm - why?  Shouldn't it be greedy and go until the last one?  What am
I
> missing?

Hmm - you are correct - the greedy behavior of . always does something
different than what I expect.

If you change:
    var regex = /<(\w+).*?id="(\w+)".*?>((.|\n|\r)*)<\/\1>/;
to:
    var regex = /<(\w+)[^>]*id="(\w+)"[^>]*>((.|\n|\r)*)<\/\1>/;

and match it against:

results = regex.exec("<html><body><span id=\"foo\">FOO<span
id=\"bar\">BAR</span></span></body></html>")

You will get:

results[0] = <span id=\"foo\">FOO<span id=\"bar\">BAR</span></span>
results[1] = span
results[2] = foo
results[3] = FOO<span id=\"bar\">BAR</span>
results[4] = >


Tested with the following in Firefox's JavaScript console:
var rx=(/<(\w+)[^>]*id="(\w+)"[^>]*>((.|\n|\r)*)<\/\1>/) ;  var
txt="<html><body><span id=\"foo\">FOO<span
id=\"bar\">BAR</span></span></body></html>";
alert("rx="+rx+"\ntxt="+txt+"\nresults="+rx.exec(txt).join("\n"))


More information about the Seaside mailing list