当前位置: 首页>>代码示例>>C#>>正文


C# RegexCompilationInfo.MatchTimeout属性代码示例

本文整理汇总了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);
   }
}
开发者ID:.NET开发者,项目名称:System.Text.RegularExpressions,代码行数:26,代码来源:RegexCompilationInfo.MatchTimeout

示例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);
      }                                                         
   }
}
开发者ID:.NET开发者,项目名称:System.Text.RegularExpressions,代码行数:29,代码来源:RegexCompilationInfo.MatchTimeout

输出:

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


注:本文中的System.Text.RegularExpressions.RegexCompilationInfo.MatchTimeout属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。