Re: Regular Expressions

Martin Ward <>
17 Oct 2004 16:03:39 -0400

          From comp.compilers

Related articles
Regular Expressions (2004-10-09)
Re: Regular Expressions (Eric Bodden) (2004-10-12)
Re: Regular Expressions (Randall Hyde) (2004-10-12)
Re: Regular Expressions (Sylvain Schmitz) (2004-10-12)
Re: Regular Expressions (Martin Ward) (2004-10-12)
Re: Regular Expressions (2004-10-12)
Re: Regular Expressions (David Z Maze) (2004-10-12)
Re: Regular Expressions (Martin Ward) (2004-10-17)
Re: Regular Expressions (ChokSheak Lau) (2004-10-21)
Re: regular expressions wendt@CS.ColoState.EDU (1993-03-22)
Regular Expressions (trejo ortiz alejandro augusto) (1995-10-16)
Re: Regular Expressions (Mitchell Perilstein) (1995-10-23)
Re: Regular Expressions (1995-10-29)
Re: Regular Expressions (Colm O'Dunlaing) (1995-10-31)
[3 later articles]
| List of all articles for this month |

From: Martin Ward <>
Newsgroups: comp.compilers
Date: 17 Oct 2004 16:03:39 -0400
Organization: Compilers Central
References: 04-10-069 04-10-100
Keywords: lex
Posted-Date: 17 Oct 2004 16:03:39 EDT

On Tuesday 12 Oct 2004 5:56 am, Torben Ęgidius Mogensen wrote:
> A regular expression can not
> handle arbitray nesting depts, so you would either need to use a
> counter in the action of the regular expression or limit yourself to a
> fixed limit on the number of nested tables and write a regular
> expression for each level of nesting.

If you are using perl, there is another option for solving the nested
parentheses problem, which is to write a recursive regular expression:

my $np;
$np = qr{
                      (?: # Non-capture group
                            (?> [^( )]+ ) # Non-capture group w/o backtracking
                            (??{ $np }) # Group with matching parens

This generates a rexexp $np which matches:
'(' followed by zero or more iterations of:
      either a string with no parentheses
      or something which matches $np,
followed by ')'.

In effect you have a lazy description of an infinite regexp: so no counter
is needed, nor is there a limit on the depth of parentheses.

Martin Erdos number: 4
G.K.Chesterton web site:

Post a followup to this message

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