PCRE has a feature called recursive pattern, which can be used to match nested subgroups. For example, consider the “grammar”
Q -> w | '[' A ';' Q* ','? Q* ']' | '<' A '>'
A -> (Q | ',')*
// to match ^A$.
It can be done in PCRE with the pattern
^((?:,|(w|[(?1);(?2)*,?(?2)*]|<(?1)>))*)$
(Example test case: http://www.ideone.com/L4lHE)
There is no recursive pattern in .NET. Instead, it provides balancing groups for stack-based manipulation for matching simple nested patterns.
Is it possible to convert the above PCRE pattern into .NET Regex style?
(Yes I know it’s better not to use regex in for this. It’s just a theoretical question.)
Similar:
- Recursive regex in PHP Hi to all! Could you please explain to me a little about a recursive regular expression in PHP PCRE? So, for example I have general...
- Numerical Pattern Matching A project I’m researching requires some numerical pattern matching. My searches haven’t turned up many relevant hits since most results tend to be around text...
- C# reliable way to pattern match? At the moment I am trying to match patterns such as text text date1 date2 So I have regular expressions that do just that. However,...
- Need a software load balancer that can match URL patterns for traffic routing. I need to balance traffic to several HTTP listeners. They are in two groups for two different purposes. To illustrate… 10.0.0.1 10.0.1.1 10.0.1.2 10.0.2.1 10.0.2.2...
- design patterns for messenger Hi, Id like use some design patterns for messenger. Messenger functions are : *Login user on server *Load friends into contact list *Receive / Send...
Tags: grammar, recursive pattern, subgroups