本文整理汇总了C#中RegexOptions类的典型用法代码示例。如果您正苦于以下问题:C# RegexOptions类的具体用法?C# RegexOptions怎么用?C# RegexOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RegexOptions类属于命名空间,在下文中一共展示了RegexOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test
//public static void Test_Regex(string sRegex, string sInput)
//{
// Test_Regex(sRegex, sInput, RegexOptions.Compiled | RegexOptions.IgnoreCase);
//}
public static void Test(string regexPattern, string text, RegexOptions options = RegexOptions.Compiled | RegexOptions.IgnoreCase)
{
Regex regex = new Regex(regexPattern, options);
Trace.WriteLine("Regex : {0}", regexPattern);
Trace.WriteLine("Input : {0}", text);
Match match = regex.Match(text);
//string s;
//if (match.Success) s = "found"; else s = "not found";
//Trace.WriteLine("Result : {0}", s);
if (!match.Success)
Trace.WriteLine("Result : not found");
int n = 1;
while (match.Success)
{
Trace.WriteLine("Result : found no {0}", n++);
for (int i = 0; i < match.Groups.Count; i++)
{
Trace.WriteLine("Groups[{0}] : \"{1}\"", i, match.Groups[i].Value);
if (match.Groups[i].Captures.Count > 1)
{
for (int j = 0; j < match.Groups[i].Captures.Count; j++)
{
Trace.WriteLine(" Capture[{0}] : \"{1}\"", j, match.Groups[i].Captures[j]);
}
}
}
match = match.NextMatch();
}
}
示例2: IsMatch
/// <summary>
/// Gets whether a <see cref="Regex" /> with the specified pattern finds a match in the specified input
/// <see cref="String" />.
/// </summary>
/// <exception cref="ArgumentNullException">The input can not be null.</exception>
/// <exception cref="ArgumentNullException">The pattern can not be null.</exception>
/// <exception cref="ArgumentNullException">The timeout can not be null.</exception>
/// <param name="input">The <see cref="String" /> to search for a match.</param>
/// <param name="pattern">The regular expression pattern used by the <see cref="Regex" />.</param>
/// <param name="options">The regular expression options used by the <see cref="Regex" />.</param>
/// <param name="timeOut">The timeout for the match operation.</param>
/// <returns>A value of true if the regular expression finds a match, otherwise false.</returns>
public static Boolean IsMatch( this String input, String pattern, RegexOptions options, TimeSpan timeOut )
{
input.ThrowIfNull( nameof( input ) );
pattern.ThrowIfNull( nameof( pattern ) );
return Regex.IsMatch( input, pattern, options, timeOut );
}
示例3: Parse
/*
* This static call constructs a RegexTree from a regular expression
* pattern string and an option string.
*
* The method creates, drives, and drops a parser instance.
*/
internal static RegexTree Parse(string re, RegexOptions op)
{
int end;
var pcreOptions = TrimPcreRegexOption(re, out end);
var pattern = TrimDelimiters(re, end);
RegexParser p;
RegexNode root;
string[] capnamelist;
p = new RegexParser((op & RegexOptions.CultureInvariant) != 0 ? CultureInfo.InvariantCulture : CultureInfo.CurrentCulture);
p._options = op;
p.SetPattern(pattern);
p.CountCaptures();
p.Reset(op);
root = p.ScanRegex();
if (p._capnamelist == null)
capnamelist = null;
else
capnamelist = p._capnamelist.ToArray();
return new RegexTree(root, p._caps, p._capnumlist, p._captop, p._capnames, capnamelist, op);
}
示例4: RegexAttribute
private RegexAttribute(string pattern, RegexOptions options, bool optionsSpecified, Type compiledRegexType)
{
this.pattern = pattern;
this.options = options;
this.optionsSpecified = optionsSpecified;
this.compiledRegexType = compiledRegexType;
}
示例5: MustNotMatchRegexAttribute
/// <summary>
/// Primary constructor.
/// </summary>
/// <param name="pattern">The regular expression pattern to match
/// against.</param>
public MustNotMatchRegexAttribute(string pattern)
{
Pattern = pattern;
_options = RegexOptions.None;
_regEx = new Regex(pattern, _options);
}
示例6: RegexCompilationInfo
/// <devdoc>
/// <para>
/// [To be supplied]
/// </para>
/// </devdoc>
public RegexCompilationInfo(String pattern, RegexOptions options, String name, String fullnamespace, bool ispublic) {
Pattern = pattern;
Name = name;
Namespace = fullnamespace;
this.options = options;
isPublic = ispublic;
}
示例7: DynamicRegexArticleComparer
public DynamicRegexArticleComparer(string comparator, RegexOptions options)
{
Comparator = comparator;
Options = (options & ~RegexOptions.Compiled);
// Create a regex to try it out. Throws an exception if there's a regex error
new Regex(Tools.ApplyKeyWords("a", comparator), options);
}
示例8: StringRules
/// <summary>
/// Initializes a new instance of the <see cref="StringRules"/> class.
/// </summary>
/// <param name="minLength">The minimum string length allowed.</param>
/// <param name="maxLength">The maximum string length allowed.</param>
/// <param name="allowedChars">The set of allowed characters.</param>
/// <param name="regexOptions">The additional regex options to use.</param>
/// <param name="customerFilters">An optional collection of custom <see cref="Regex"/> patterns that describe
/// additional restrictions.</param>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="minLength"/> is less than 0.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="maxLength"/> is less than
/// <paramref name="minLength"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="minLength"/> is greater than
/// <see cref="ushort.MaxValue"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="maxLength"/> is greater than
/// <see cref="ushort.MaxValue"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="allowedChars"/> contains no defined groups.</exception>
/// <exception cref="ArgumentException">At least one character group must be allowed.</exception>
public StringRules(int minLength, int maxLength, CharType allowedChars, RegexOptions regexOptions = RegexOptions.None,
IEnumerable<Regex> customerFilters = null)
{
if (minLength < 0)
throw new ArgumentOutOfRangeException("minLength");
if (maxLength < minLength)
throw new ArgumentOutOfRangeException("maxLength");
if (minLength > ushort.MaxValue)
throw new ArgumentOutOfRangeException("minLength");
if (maxLength > ushort.MaxValue)
throw new ArgumentOutOfRangeException("maxLength");
if ((int)allowedChars == 0)
throw new ArgumentException("At least one character group must be allowed.", "allowedChars");
_minLength = (ushort)minLength;
_maxLength = (ushort)maxLength;
_allowedChars = allowedChars;
var regexStr = BuildRegexString(minLength, maxLength, allowedChars);
_regex = new Regex(regexStr, RegexOptions.Compiled | regexOptions);
if (customerFilters != null)
_customFilters = customerFilters.ToCompact();
}
示例9: IsMatch
/// <summary>
/// Проверка, что строка соответствует заданному шаблону
/// </summary>
/// <param name="testString">Проверяемая строка</param>
/// <param name="template">Шаблон</param>
/// <param name="options">Параметры сравнения</param>
/// <param name="errorMessageFormatString">Текст ошибки</param>
/// <param name="errorMessageArgs">Параметры для сообщения об ошибке</param>
public static void IsMatch(string testString, string template, RegexOptions options, string errorMessageFormatString, params object[] errorMessageArgs)
{
if (testString == null || !Regex.IsMatch(testString, template, options))
{
Throw(errorMessageFormatString, errorMessageArgs);
}
}
示例10: RegexNode
internal RegexNode(int type, RegexOptions options, int m, int n)
{
this._type = type;
this._options = options;
this._m = m;
this._n = n;
}
示例11: Regex
public Regex(string pattern, RegexOptions options)
{
this.refsInitialized = false;
if (pattern == null)
{
throw new ArgumentNullException();
}
if ((options < RegexOptions.None) || ((((int) options) >> 9) != 0))
{
throw new ArgumentOutOfRangeException();
}
if (((options & RegexOptions.ECMAScript) != RegexOptions.None) && ((options & ~(RegexOptions.CultureInvariant | RegexOptions.ECMAScript | RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase)) != RegexOptions.None))
{
throw new ArgumentOutOfRangeException();
}
string text1 = options + ":" + pattern;
this.pattern = pattern;
this.roptions = options;
RegexTree t = RegexParser.Parse(pattern, this.roptions);
this.capnames = t._capnames;
this.capslist = t._capslist;
this.code = RegexWriter.Write(t);
this.caps = this.code._caps;
this.capsize = this.code._capsize;
}
示例12: GrepSink
public GrepSink (IMiniStreamSink dest, string[] regexes, RegexOptions options) {
this.dest = dest;
this.regexes = new Regex[regexes.Length];
for (int i = 0; i < regexes.Length; i++)
this.regexes[i] = new Regex (regexes[i], options);
}
示例13: FactoryTypeFromCode
internal Type FactoryTypeFromCode(RegexCode code, RegexOptions options, string typeprefix)
{
base._code = code;
base._codes = code._codes;
base._strings = code._strings;
base._fcPrefix = code._fcPrefix;
base._bmPrefix = code._bmPrefix;
base._anchors = code._anchors;
base._trackcount = code._trackcount;
base._options = options;
string str3 = Interlocked.Increment(ref _typeCount).ToString(CultureInfo.InvariantCulture);
string typename = typeprefix + "Runner" + str3;
string str2 = typeprefix + "Factory" + str3;
this.DefineType(typename, false, typeof(RegexRunner));
this.DefineMethod("Go", null);
base.GenerateGo();
this.BakeMethod();
this.DefineMethod("FindFirstChar", typeof(bool));
base.GenerateFindFirstChar();
this.BakeMethod();
this.DefineMethod("InitTrackCount", null);
base.GenerateInitTrackCount();
this.BakeMethod();
Type newtype = this.BakeType();
this.DefineType(str2, false, typeof(RegexRunnerFactory));
this.DefineMethod("CreateInstance", typeof(RegexRunner));
this.GenerateCreateInstance(newtype);
this.BakeMethod();
return this.BakeType();
}
示例14: RegexTrial
public RegexTrial (string pattern, RegexOptions options, string input, string expected)
{
this.pattern = pattern;
this.options = options;
this.input = input;
this.expected = expected;
}
示例15: GetValueFromText
private static string GetValueFromText(string text, string regex, RegexOptions option = RegexOptions.None)
{
MatchCollection mat = Regex.Matches(text, regex, option);
if (mat.Count > 0)
return mat[0].Groups["token"].ToString().Trim(trimChars: new char[] { ' ' });
return string.Empty;
}