Boost logo

Boost :

From: Lorenzo Bettini (bettini_at_[hidden])
Date: 2007-05-01 11:36:16

Phil Endecott wrote:
> Lorenzo wrote:
>> is there a way to specify open and closed parenthesis with a
>> regular expression syntax? For instance, if I'd want to specify a
>> single regular expression that matches both (foo) and [foo] and {foo}?
> Lorenzo,
> Matching parentheses to arbitrary depth is, like matching palindromes,
> a textbook example of something that cannot be done with a regular
> language and instead needs a context-free language. Google for
> "chomsky hierarchy palindrome" for some background material. Of
> course, it's possible that some regexp library somewhere has a hack to
> add this functionality. But fundamentally, you need a more
> sophisticated parser.

Hi Phil

yes I know about that, but since regex supports backreferences and
conditionals, I thought that this might be implemented by a combination
of these two mechanisms... indeed John Maddock answered to this thread
right with a manual solution using backreferences and conditionals...

so I thought a regular expression syntax could already be provided to
match these...

I'm using regular expressions for this software that highlights programs, and
it assumes that the program itself is correct. Thus, I assume that
parenthesis (and brackets - sorry, in Italian both (, [ and { are called
parenthesis :-) are balanced, and with greedy regular expressions,
nested parenthesis are already handled...


Lorenzo Bettini, PhD in Computer Science, DSI, Univ. di Firenze
ICQ# lbetto, 16080134     (GNU/Linux User # 158233)

Boost list run by bdawes at, gregod at, cpdaniel at, john at