Re: requiring balanced parens in a regexp?

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
10 Nov 2006 13:18:47 -0500

          From comp.compilers

Related articles
requiring balanced parens in a regexp? petermichaux@gmail.com (Peter Michaux) (2006-11-10)
Re: requiring balanced parens in a regexp? petermichaux@gmail.com (Peter Michaux) (2006-11-10)
Re: requiring balanced parens in a regexp? mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2006-11-10)
Re: requiring balanced parens in a regexp? martin@gkc.org.uk (Martin Ward) (2006-11-10)
Re: requiring balanced parens in a regexp? haberg@math.su.se (2006-11-10)
Re: requiring balanced parens in a regexp? alexc@TheWorld.com (Alex Colvin) (2006-11-10)
Re: requiring balanced parens in a regexp? cfc@shell01.TheWorld.com (Chris F Clark) (2006-11-10)
| List of all articles for this month |
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Newsgroups: comp.compilers
Date: 10 Nov 2006 13:18:47 -0500
Organization: cbb software GmbH
References: 06-11-039
Keywords: parse
Posted-Date: 10 Nov 2006 13:18:47 EST

On 10 Nov 2006 00:17:42 -0500, Peter Michaux wrote:


> In the following string I would like to find the word that comes after
> "test" as long as test is not inside parenthesis. In this example the
> match would be "two".
>
> "the (test one) test two"
>
> I found some indication that Perl regexp can do this with some sort of
> recursive regexp. Can JavaScript regular expressions ensure that all
> parentheses to the right of "test" are closed before proclaiming a
> match? If so how? If not must I walk through the string counting how
> nested each character is?


There are two options, either you write a parser of your own or else
you take a more powerful class of patterns, because as our moderator
has said, RE cannot match balanced brackets (and other nested stuff).


As for the second option, SNOBOL patterns can do it:


http://www.infeig.unige.ch/support/ada/gnatlb/g-spitbo.html
http://www.dmitry-kazakov.de/match/match.htm


Basically the pattern should skip any text in brackets. Quotes and
comments are dealt in a similar way.


[ http://www.snobol4.org contains further SNOBOL resources ]


--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.