• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# RegexOptions类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中RegexOptions的典型用法代码示例。如果您正苦于以下问题:C# RegexOptions类的具体用法?C# RegexOptions怎么用?C# RegexOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RegexOptions类属于命名空间,在下文中一共展示了RegexOptions类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
            }
        }
开发者ID:labeuze,项目名称:source,代码行数:34,代码来源:Test_Regex.cs


示例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 );
        }
开发者ID:MannusEtten,项目名称:Extend,代码行数:19,代码来源:String.IsMatch.cs


示例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);
        }
开发者ID:iolevel,项目名称:peachpie,代码行数:32,代码来源:RegexParser.cs


示例4: RegexAttribute

 private RegexAttribute(string pattern, RegexOptions options, bool optionsSpecified, Type compiledRegexType)
 {
     this.pattern = pattern;
     this.options = options;
     this.optionsSpecified = optionsSpecified;
     this.compiledRegexType = compiledRegexType;
 }
开发者ID:ChiangHanLung,项目名称:PIC_VDS,代码行数:7,代码来源:RegexAttribute.cs


示例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);
        }
开发者ID:reubeno,项目名称:NClap,代码行数:12,代码来源:MustNotMatchRegExAttribute.cs


示例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;
 }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:12,代码来源:regexcompilationinfo.cs


示例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);
 }
开发者ID:svn2github,项目名称:autowikibrowser,代码行数:7,代码来源:RegexComparers.cs


示例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();
        }
开发者ID:wtfcolt,项目名称:game,代码行数:43,代码来源:StringRules.cs


示例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);
     }
 }
开发者ID:svn2github,项目名称:ecm7migrator,代码行数:15,代码来源:Require.cs


示例10: RegexNode

 internal RegexNode(int type, RegexOptions options, int m, int n)
 {
     this._type = type;
     this._options = options;
     this._m = m;
     this._n = n;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:RegexNode.cs


示例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;
 }
开发者ID:memsom,项目名称:dotNetAnywhere-wb,代码行数:25,代码来源:Regex.cs


示例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);
		}
开发者ID:emtees,项目名称:old-code,代码行数:7,代码来源:GrepSink.cs


示例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();
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:30,代码来源:RegexTypeCompiler.cs


示例14: RegexTrial

		public RegexTrial (string pattern, RegexOptions options, string input, string expected)
		{
			this.pattern = pattern;
			this.options = options;
			this.input = input;
			this.expected = expected;
		}
开发者ID:nlhepler,项目名称:mono,代码行数:7,代码来源:RegexTrial.cs


示例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;
 }
开发者ID:Krishjs,项目名称:Bns.Web,代码行数:7,代码来源:PdfExtractor.cs


示例16: RegexRouteConstraintBase

 protected RegexRouteConstraintBase(string pattern, RegexOptions options)
 {
     Pattern = pattern;
     // shouldn't these be included in the derrived classes by default: RegexOptions.CultureInvariant | RegexOptions.IgnoreCase?
     Options = options;  //no need to tell user that it is 'compiled' option...so do not include in public options
     CompiledExpression = new Regex(pattern, options | RegexOptions.Compiled);
 }
开发者ID:gregmac,项目名称:AttributeRouting,代码行数:7,代码来源:RegexRouteConstraintBase.cs


示例17: Reformat

		public string Reformat (RegexOptions options,
			string reformattedPattern,
			PatternGrouping patternGrouping) {
			if (!HasConstruct (reformattedPattern, options)) {
				return reformattedPattern;
			}

			if (patternGrouping.GroupCount >= 0 && patternGrouping.SameGroupsFlag) {
				return null;
			}

			Matcher m = JavaUtils.Matcher (reformattedPattern, NUMBER_BACK_REFERENCE_PATTERN);
			if (m.find ()) {
				reformattedPattern = ReplaceGroupNumber (m, reformattedPattern, patternGrouping, options);
				if (reformattedPattern == null)
					return null;
			}

			m = JavaUtils.Matcher(reformattedPattern, NAME_1_BACK_REFERENCE_PATTERN);
			if (m.find ()) {
				reformattedPattern = ReplaceGroupName (m, reformattedPattern, patternGrouping, options);
				if (reformattedPattern == null)
					return null;
			}

			m = JavaUtils.Matcher(reformattedPattern, NAME_2_BACK_REFERENCE_PATTERN);
			if (m.find ()) {
				reformattedPattern = ReplaceGroupName (m, reformattedPattern, patternGrouping, options);
				if (reformattedPattern == null)
					return null;
			}

			return reformattedPattern;
		}
开发者ID:carrie901,项目名称:mono,代码行数:34,代码来源:BackReferenceConstruct.jvm.cs


示例18: RegEx

 public RegEx(string pattern, string name, bool expectedMatch = true,
     RegexOptions options = RegexOptions.Compiled)
     : base(pattern, options)
 {
     Name = name;
     ExpectedMatch = expectedMatch;
 }
开发者ID:rmandvikar,项目名称:PasswordValidator,代码行数:7,代码来源:RegEx.cs


示例19: Parse

 private ParamCollection Parse(ref string s, string pattern, bool remove, string tag, RegexOptions options)
 {
     ParamCollection cmd = new ParamCollection(Name);
     Regex rex = new Regex(pattern, options);
     Match m1 = rex.Match(s);
     while (m1.Success)
     {
         string param = m1.Groups[PARAM].Value;
         string arg = m1.Groups[ARGS].Value;
         if (param != null)
         {
             param = param.TrimEnd(' ');
             ArgCollection prm = cmd.Add(param, new ArgCollection(param, tag));
             if (arg != null)
             {
                 arg = arg.TrimEnd(' ');
                 if (!string.IsNullOrEmpty(arg))
                 {
                     prm.Add(arg);
                 }
             }
         }
         if (remove)
         {
             s = s.Remove(m1.Index, m1.Length).Trim();
             m1 = rex.Match(s);
         }
         else
         {
             m1 = rex.Match(s, m1.Index + m1.Length);
         }
     }
     return cmd;
 }
开发者ID:AlexandrSurkov,项目名称:PKStudio,代码行数:34,代码来源:PKArgParser.cs


示例20: Split

 public void Split(string pattern, string input, RegexOptions options, int count, int start, string[] expected)
 {
     bool isDefaultStart = RegexHelpers.IsDefaultStart(input, options, start);
     bool isDefaultCount = RegexHelpers.IsDefaultStart(input, options, count);
     if (options == RegexOptions.None)
     {
         // Use Split(string), Split(string, string), Split(string, int) or Split(string, int, int)
         if (isDefaultStart && isDefaultCount)
         {
             // Use Split(string) or Split(string, string)
             Assert.Equal(expected, new Regex(pattern).Split(input));
             Assert.Equal(expected, Regex.Split(input, pattern));
         }
         if (isDefaultStart)
         {
             // Use Split(string, int)
             Assert.Equal(expected, new Regex(pattern).Split(input, count));
         }
         // Use Split(string, int, int)
         Assert.Equal(expected, new Regex(pattern).Split(input, count, start));
     }
     if (isDefaultStart && isDefaultCount)
     {
         // Use Split(string, string, RegexOptions)
         Assert.Equal(expected, Regex.Split(input, pattern, options));
     }
     if (isDefaultStart)
     {
         // Use Split(string, int)
         Assert.Equal(expected, new Regex(pattern, options).Split(input, count));
     }
     // Use Split(string, int, int, int)
     Assert.Equal(expected, new Regex(pattern, options).Split(input, count, start));
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:34,代码来源:Regex.Split.Tests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Region类代码示例发布时间:2022-05-24
下一篇:
C# Regex类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap