.NET Regular Expression Quiz
I am planning to post some of my observations about the regular expression library contained in the .NET framework. Here are some true and false regular expression questions?
1) True or false? Without using the minimal-matching regular expression operators ( ??, *?, +? ), regular expressions will match the longest string of characters that match a pattern at any given position.
2) True or false? Regex.Replace(“aaaaaabc”, “[ab]+(abc)*”, “x”) returns “x”.
3) True or false? Regex.Replace(“abcdef”, “abc|[abcdef]+)”, “x”) returns “x”.
4) True or false? Regex.Replace(“a”, “a*?”, “x”) returns “xax”.
5) True or false? The Regex class implements regular expressions using state matchines (ie, either deterministic or nondeterministic finite automata from the theory of automata).
6) True or false? If text is a string and regex is a preconstructed Regex(“abcdefghi”), text.IndexOf(“abcdefghi”) outperforms regex.Match(text).
7) True or false? Some short simple Regex expressions can take more than a lifetime to perform, effectively hanging the computer. (In computer science jargon, .NET regular expressions can potentially exhibit exponential running time).