
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 http://www.gnu.org/software/src-highlite 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 -- Lorenzo Bettini, PhD in Computer Science, DSI, Univ. di Firenze ICQ# lbetto, 16080134 (GNU/Linux User # 158233) HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com http://www.gnu.org/software/src-highlite http://www.gnu.org/software/gengetopt http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net