regex-le 0.3.1

Find every regex in a codebase, and report which can be driven into catastrophic backtracking
1
2
3
4
5
6
7
8
9
10
11
using System.Text.RegularExpressions;

class Validate {
	// Verbatim string: the source as written
	static readonly Regex Nested = new Regex(@"(a+)+");
	// Quoted string: escapes a level
	static readonly Regex Escaped = new Regex("\\d{4}");
	// The static form takes the subject first and the pattern second
	static bool Check(string s) => Regex.IsMatch(s, @"(a|ab)+");
	static string Strip(string s) => Regex.Replace(s, "\\s+", "");
}