Re: Stack-based behaviour of Regexes

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Kevin Burton (KevinBurton_at_discussions.microsoft.com)
Date: 08/31/04


Date: Mon, 30 Aug 2004 21:07:15 -0700

I had thought of that and that will be one possible work-around. I would like
to avoid bringing in the DOM for two reasons:

1) I am concerned about the overhead. These are relatively short strings
(most less than 1K) and the DOM seems overkill and costly in terms of cycles
and memory for just these strings. Regex can be compiled and it just seems
faster although I have not done benchmarks on it. I know there are some
constructs in the DOM that are VERY costly. Simple things like counting
elements were killing a web application that we had.
2) I want to understand how to handle nested constructs using regular
expressions. It seems to work OK for single character open and close entities
like parenthesis but it should be extendable to entities greater than one
character.

I just need the start and end of a possibly nested structure. So for example

<A> This is some text
<OPTIONAL>This is some <OPTIONAL>optional text</OPTIONAL></OPTIONAL>
<B>This is some B text
<OPTIONAL>This is some more optional text </OPTIONAL>
</A>

For the first <OPTIONAL> tag I would like the index into the string where
this begins and where the corresponding </OPTIONAL> tag ends (so the index
would essentially point to the beginning of <B>). For the next <OPTIONAL> tag
I would want the beginning and ending of that tag and content, and so forth.
If regular expressions can be used to do nested parenthesis then can't a
regular expression be put together to handle nested tags?

Kevin

"Mike D Sutton" wrote:

> > Have you been able to expand this to more than one characters? I have nexted
> > XML tags that I would like to do the same thing with. Here is my best guess
> > (it does not work). Basically the tag is <OPTIONAL> and the end tag is
> > </OPTIONAL>. These can be nested with other tags in between. The regex I have
> > shown below allows for attributes.
>
> Why not just use the MSXML DOM and XPath queries to find your data within the XML file? Are you just looking for <OPTIONAL> tags or
> something specific within them?
> Hope this helps,
>
> Mike
>
>
> - Microsoft Visual Basic MVP -
> E-Mail: EDais@mvps.org
> WWW: http://www.mvps.org/EDais/
>
>
>



Relevant Pages

  • Re: Stack-based behaviour of Regexes
    ... These are relatively short strings ... and the DOM seems overkill and costly in terms of cycles ... this begins and where the corresponding tag ends (so the index ... If regular expressions can be used to do nested parenthesis then can't a ...
    (microsoft.public.vb.general.discussion)
  • Re: Stack-based behaviour of Regexes
    ... These are relatively short strings ... and the DOM seems overkill and costly in terms of cycles ... this begins and where the corresponding tag ends (so the index ... If regular expressions can be used to do nested parenthesis then can't a ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Dynamic Table
    ... in some browsers, if there is any whitespace between the opening tag and tag, a #text node will be inserted in the DOM. ... The firstChild of the TD will be the text node, ... If the inputs are in a form, the DOM 0 forms methods seem much simpler. ... Learn to write robust code - the above example isn't intended for that purpose, it's just an example to help you get to the finished product. ...
    (comp.lang.javascript)
  • Re: Search for values in between two values in a string?
    ... If the application is on the client side, then you can just pure JavaScript or JSCRIPT or VBSCRIPT to access the Document.* methods and properties and events. ... but that finds a tag id=value, ... DOM has GetElementByTag and GetElementByName, ... In fact, jQuery is so small, fast and sweet, Microsoft has announced full jQuery support in ASP.NET. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: REgular expression to match a XML tag
    ... I am trying to match an XML tag using JS regular expressions. ... regular expressions are based on, to parse a context-free language, such as ...
    (comp.lang.javascript)