本文整理汇总了C#中RegexOptions.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# RegexOptions.ToString方法的具体用法?C# RegexOptions.ToString怎么用?C# RegexOptions.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RegexOptions
的用法示例。
在下文中一共展示了RegexOptions.ToString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ValidateStringIsMatchForRegularExpression
/// <summary>
/// Make sure a string matches the specified regular expression
/// </summary>
/// <param name="argument">The argument to validate</param>
/// <param name="name">The name of the argument</param>
/// <param name="source">The source of the validation check</param>
/// <param name="regularExpression">The regular expression to validate against</param>
/// <param name="regexOptions">Options to use when testing for match</param>
public static void ValidateStringIsMatchForRegularExpression(string argument, string name, string source, string regularExpression, RegexOptions regexOptions)
{
ValidateNonNullReference(argument, name, source);
if (!Regex.IsMatch(argument, regularExpression, regexOptions))
{
ValidateCallerInfo(ref name, ref source);
string errorMessage = string.Format(Thread.CurrentThread.CurrentCulture, DiagnosticsResources.InvalidRegExpresionErrorFormat, source, name, argument, regularExpression, regexOptions.ToString());
//EventLogger.WriteMessage(source, errorMessage, MessageType.Error);
throw new ArgumentException(errorMessage, name);
}
}
示例2: displayHeader
private static void displayHeader(string input, string pattern, RegexOptions options)
{
Console.WriteLine("Input: {0}", input.Show());
Console.WriteLine("Pattern: {0}", pattern.ShowVerbatim());
if (options != RegexOptions.None)
Console.WriteLine("Options: [{0}]", options.ToString());
}
示例3: formatException
private static string formatException(string input, string pattern, RegexOptions options, Exception ex)
{
const string indent = " ";
string message = string.Format("Comparing with .NET Regex: Input={0}, Pattern={1}{2}\n",
input.Show(),
pattern.ShowVerbatim(),
options != RegexOptions.None ?
string.Format(", Options=[{0}]", options.ToString()) :
"") +
ex.Message;
message = indent + message.Replace("\n", "\n" + indent);
return message;
}
示例4: testRegexMatches
private static void testRegexMatches(string input, string pattern, RegexOptions options, int times)
{
Console.WriteLine("Pattern: {0}", pattern.ShowVerbatim());
if (options != RegexOptions.None)
Console.WriteLine("Options: [{0}]", options.ToString());
MemoryProfiler memoryProfiler;
if (useMemoryProfiler)
memoryProfiler = MemoryProfiler.StartNew();
Stopwatch stopwatch = Stopwatch.StartNew();
MatchCollection2 matches = null;
//Msoft.MatchCollection matches = null;
for (int i = 0; i < times; i++)
matches = new Regex2(pattern, AlgorithmType.Backtracking, options).Matches(input);
//matches = new Msoft.Regex(pattern, RegexAssert.ToMsoftRegexOptions(options)).Matches(input);
if (useMemoryProfiler)
memoryProfiler.Reset();
Console.WriteLine("Matches: {0:#,##0}", matches.Count);
//string v;
//foreach (var m in matches.Cast<Match2>())
////foreach (var m in matches.Cast<Msoft.Match>())
// v = m.Value;
decimal elapsed = ((decimal)stopwatch.ElapsedMilliseconds) / 1000;
if (useMemoryProfiler)
{
long deltaBefore = memoryProfiler.DeltaValue;
memoryProfiler.CollectGC();
long deltaAfter = memoryProfiler.DeltaValue;
if (matches.Count > 0)
Console.WriteLine("Last: {0:#,##0} chars", matches[matches.Count - 1].Value.Length);
Console.WriteLine("Memory: {0,10:#,##0} bytes", deltaBefore);
Console.WriteLine("AfterGC: {0,10:#,##0} bytes", deltaAfter);
}
Console.WriteLine("Time: {0:#0.000} sec.\n", elapsed);
}