Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the operator precedence documented for the .NET Regex class?

Where is the order of operator precedence documented for the .NET Regex class?

I see this, but that's for JScript.

Also, it appears this is not affected by RegexOptions.ECMAScript, but confirmation would be helpful.

like image 824
Matthew Flaschen Avatar asked Nov 04 '22 05:11

Matthew Flaschen


2 Answers

I don't think the real answer is as simple as you'd like. The short (and incomplete) answer is simply "all expressions are evaluated left to right" ...

For the long answer go here.

http://msdn.microsoft.com/en-us/library/e347654k.aspx

The .NET Framework regular expression engine is a backtracking regular expression matcher that incorporates a traditional Nondeterministic Finite Automaton (NFA) engine ... traditional NFA engines perform pattern matching, their processing order is driven by the regular expression pattern. As it processes a particular language element, the engine uses greedy matching; that is, it matches as much of the input string as it possibly can. But it also saves its state after successfully matching a subexpression. If a match eventually fails, the engine can return to a saved state so it can try additional matches.

Edit: Forgot to answer the second part of your question.

With regard to RegexOptions.ECMAScript, you can reference these docs:

http://msdn.microsoft.com/en-us/library/yd1hzczs.aspx

The behavior of ECMAScript and canonical regular expressions differs in three areas: character class syntax, self-referencing capturing groups, and octal versus backreference interpretation.

It doesn't look like "order" is affected, but there could be other issues. The docs do a good job of illustrating the differences.

like image 102
Angel Marquez Avatar answered Nov 14 '22 21:11

Angel Marquez


This was asked a long time ago, but not answered.

The .Net regex operator precidence is defined at the bottom of the Regular Expression Syntax page 1.

like image 30
Donald Rich Avatar answered Nov 14 '22 22:11

Donald Rich