[Javascript] regexp - how to exclude a substring?
Paul Novitski
paul at novitskisoftware.com
Mon May 23 18:00:24 CDT 2005
[Sorry about that: here's the last half of my previous message done
differently so it won't be rendered as html. I'll mark up tags like {html}
instead of using < and >.]
My current strategy is to initialize the template engine by walking the
document recording the lineage of each element:
{html} 0:html
{body} 1:html body
{div id="content"} 2:html body div#content
{h2} 3:html body div#content h2
{/h2}
{p class="intro"} 4:html body div#content p.intro
{span} 5:html body div#content p.intro span
{/span}
{/p}
{/div}
{ul id="nav" class="menu"} 6:html body ul#nav.menu
...
(I wonder if this is how some rendering engines work internally, so they
don't have to keep re-parsing the document?)
Then I can search those lineage strings for the matches I want. Assuming
that every tag name is preceded by a space, and that #ids come before
.classes, then this regex should work to pinpoint the desired element:
/(\d)+:.* div.* p[^ ]*\.intro.* span/
will match:
div p.intro span
in:
5:html body div#content p.intro span
Then my parenthetical expression (\d) will yield the key number, n'est ce pas?
Paul
More information about the Javascript
mailing list