After reading Russ Cox’s regular expression articles, I became interested in porting his RE2 library to C#. These posts will describe my effort to port the entire library, which I will do in steps. I know that one could just link to the RE2 library, but I am porting this as an academic exercise to learn C# and regular expression parsing.
The full RE2 implementation is somewhat large. So, for now, I have started with something simpler: porting nfa.c, which is now committed.
There is a simple script that generates the a?^(n)a^(n) regexes and compares the performance between this simple nfa implementation and C#‘s Regex class. The results (posted below) conform exactly to those posted in the article.
n, nfa match time (s), C# Regex match time (s):