Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are regular expressions implemented in .NET?

I have just read this interesting article about the implementation details for various languages that support regular expressions.

It describes an alternative implementation of regular expressions that uses non-deterministic finite automatons (NFAs) versus deterministic ones (DFAs). It claims that back-tracking DFA implementations (the version used in Perl, Java, and others) are susceptible to very slow performance on some particularly "pathological" regular expressions. (grep, awk, and Tcl still use DFAs, but somehow are exponentially faster)

It makes no reference to the .NET framework, but I would like to know how .NET (C# in particular) regular expressions are implemented, and how they compare in terms of performance.

Edit:

Can I assume since the answerer's article mentions .NET does backtracking, that it will be on par with Perl and Java?

like image 322
Jeff Meatball Yang Avatar asked Jul 10 '09 18:07

Jeff Meatball Yang


1 Answers

There's an awesome write-up here. He takes advantage of the fact that you can step in to the .NET framework code and see what it does, and explains how everything works. It's an excellent read.

like image 56
ojrac Avatar answered Oct 15 '22 23:10

ojrac