Questions tagged [recursive-regex]

Using a regular expression to parse an expression which contains the same expression e.g. `{ foo bar {zoo} }`

A recursive expression is an expression which contains the same expression, e.g. { foo bar {zoo} } contains an expression {...} which contains an expression {...}. Such expressions are typically expressed using a Context-free language.

However, a regular expression is only capable to parse an expression which uses a Regular Grammar.

Thus, this tag suggests that a user wants to parse a recursive expression using a regular expression, which is not possible. Typically, the user knows regular expressions, but is not really aware of the limitations, so it asks the SO community.

There is no unique solution to that problem since it depends on the grammar of the expression to parse (e.g. the user may want to limit the recursion levels).

Recursive expressions should not be confused with repeated expressions (e.g. {foo} {bar} {zoo}) which can be parsed using regular expressions.

48 questions
0
votes
4 answers

Matching *consecutive* lines that begin with an arbitrary amount of whitespace followed by a character

I am trying to match consecutive lines that starts with an arbitrary amount of space followed by the character |. I am using the s flag, so that . matches newlines. What I have so far works with a finite amount of whitespace before |. I am having…
DudeOnRock
  • 3,066
  • 3
  • 23
  • 51
0
votes
2 answers

Regular expression, back reference or alternate construct

I am trying to write a regular expression in .NET to capture the whole function from a list of functions that look something like this. public string Test1() { string result = null; foreach(var item in Entity.EntityProperties) { …
firefly
  • 265
  • 3
  • 12
0
votes
2 answers

Recursive PCRE search with patterns

This question has to do with PCRE . I have seen a recursive search for nested parentheses used with this construct: \(((?>[^()]+)|(?R))*\) The problem with this is that, while the '[^()]+' can match any character including newline, you are forced…
OnlineCop
  • 3,799
  • 19
  • 33
1 2 3
4