requiring balanced parens in a regexp?

"Peter Michaux" <petermichaux@gmail.com>
10 Nov 2006 00:17:42 -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: "Peter Michaux" <petermichaux@gmail.com>
Newsgroups: comp.compilers
Date: 10 Nov 2006 00:17:42 -0500
Organization: Compilers Central
Keywords: lex, question
Posted-Date: 10 Nov 2006 00:17:42 EST

Hi,


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?


Thank you,
Peter
[Matching parentheses is the classic problem that pure regexp's cannot
solve, because they have no way to count the number of unmatched
parens. There's a variety of ways to fake it, e.g., take your string,
replace each ([^)]+) by a space until there aren't any left, then look
for your match. Or use various extended regexps that are more like
parsers. -John]



Post a followup to this message

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