本文整理汇总了C#中System.Text.RegularExpressions.RegexCompilationInfo.MatchTimeout属性的典型用法代码示例。如果您正苦于以下问题:C# RegexCompilationInfo.MatchTimeout属性的具体用法?C# RegexCompilationInfo.MatchTimeout怎么用?C# RegexCompilationInfo.MatchTimeout使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Text.RegularExpressions.RegexCompilationInfo
的用法示例。
在下文中一共展示了RegexCompilationInfo.MatchTimeout属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Reflection;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
// Match two or more occurrences of the same character.
string pattern = @"(\w)\1+";
// Use case-insensitive matching.
var rci = new RegexCompilationInfo(pattern, RegexOptions.IgnoreCase,
"DuplicateChars", "CustomRegexes",
true, TimeSpan.FromSeconds(2));
// Define an assembly to contain the compiled regular expression.
var an = new AssemblyName();
an.Name = "RegexLib";
RegexCompilationInfo[] rciList = { rci };
// Compile the regular expression and create the assembly.
Regex.CompileToAssembly(rciList, an);
}
}
示例2: Main
//引入命名空间
using CustomRegexes;
using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
var rgx = new DuplicateChars(TimeSpan.FromSeconds(.5));
string[] values = { "Greeeeeat", "seed", "deed", "beam",
"loop", "Aardvark" };
// Display regex information.
Console.WriteLine("Regular Expression Pattern: {0}", rgx);
Console.WriteLine("Regex timeout value: {0} seconds\n",
rgx.MatchTimeout.TotalSeconds);
// Display matching information.
foreach (var value in values) {
Match m = rgx.Match(value);
if (m.Success)
Console.WriteLine("'{0}' found in '{1}' at positions {2}-{3}",
m.Value, value, m.Index, m.Index + m.Length - 1);
else
Console.WriteLine("No match found in '{0}'", value);
}
}
}
输出:
Regular Expression Pattern: (\w)\1+ Regex timeout value: 0.5 seconds eeeee// found in //Greeeeeat// at positions 2-6 ee// found in //seed// at positions 1-2 ee// found in //deed// at positions 1-2 No match found in //beam// oo// found in //loop// at positions 1-2 Aa// found in //Aardvark// at positions 0-1