本文整理汇总了C#中CharSetSolver.ConvertToRegex方法的典型用法代码示例。如果您正苦于以下问题:C# CharSetSolver.ConvertToRegex方法的具体用法?C# CharSetSolver.ConvertToRegex怎么用?C# CharSetSolver.ConvertToRegex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CharSetSolver
的用法示例。
在下文中一共展示了CharSetSolver.ConvertToRegex方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestRegex
static void TestRegex(Regex regex)
{
var solver = new CharSetSolver();
string myregex = regex.ToString();
//Regex.CompileToAssembly(new RegexCompilationInfo[] { new RegexCompilationInfo(myregex, RegexOptions.None, "EvilRegex", "RegexTransfomer", true) },
// new System.Reflection.AssemblyName("EvilRegex"));
var sfa = solver.Convert(myregex, regex.Options).RemoveEpsilons();
var sfaDet = sfa.Determinize();
var sfaMin = sfaDet.Minimize();
//solver.ShowGraph(sfa, "sfa");
//solver.ShowGraph(sfaDet, "sfaDet");
//solver.ShowGraph(sfaMin, "sfaMin");
var cs = solver.ToCS(sfaMin, true, "MyRegex", "RegexTransfomer");
var regexMin = solver.ConvertToRegex(sfaMin);
Console.WriteLine("------- given regex --------");
Console.WriteLine(myregex);
Console.WriteLine("----------------------------");
Console.WriteLine("-------- regexMin ----------");
Console.WriteLine(regexMin);
Console.WriteLine("----------------------------");
Console.WriteLine("-------- cs ----------------");
Console.WriteLine(cs.SourceCode);
Console.WriteLine("----------------------------");
string sIn = solver.GenerateMember(sfaMin);
string sOut = solver.GenerateMember(sfaMin.Complement());
string s = sIn;
int t1;
int t2;
int t3;
for (int i = 0; i < 2; i++)
{
//original regex
t1 = System.Environment.TickCount;
bool res1 = false;
for (int j = 0; j < 100000; j++)
res1 = Regex.IsMatch(s, regex.ToString(), regex.Options);
//res1 = evilregex.IsMatch(s);
t1 = System.Environment.TickCount - t1;
////minimized regex
//t2 = System.Environment.TickCount;
//bool res2 = false;
//for (int j = 0; j < 100000; j++)
// res2 = Regex.IsMatch(s, regexMin, regex.Options);
//t2 = System.Environment.TickCount - t2;
//code from minimized regex
t3 = System.Environment.TickCount;
bool res3 = false;
for (int j = 0; j < 100000; j++)
res3 = cs.IsMatch(s);
t3 = System.Environment.TickCount - t3;
Console.WriteLine(String.Format("{0}ms({1}), {2}ms({3})", t1, res1, t3, res3));
s = sOut;
}
Console.WriteLine("done...(press any key)");
Console.ReadKey();
}