Regular tool class notation for C # common

Source: Internet
Author: User

Using system;using system.collections.generic;using system.linq;using system.text;using System.text.regularexpressions;using system.collections;namespace consoleapplication1{//<summary>//String regular        Match Help class///</summary> public static class Regexhelp {///<summary>//Returns a single regular match value </summary>//<param name= "value" > String </param>//<param name= "regex" > Regular expression string </param>///<returns> String type </returns> public static string Toregexstring (the This string value                , string regex) {if (value = null) {regex re = new regex (regex); Match m = Re.                Match (value);                if (m.success) {return m.value;                } else {return null;            }} else {return null;   }     }///<summary>///return a regular match string array///</summary>//<param name= "value" >         String </param>//<param name= "regex" > Positive expression </param>//<returns> string array </returns> public static string[] Toregexstringarray (This string value, String regex) {string[] array = {            }; if (value = null) {//compatible multi-line matching pattern regex = new Regex (Regex, Regexoptions.multil                INE); MatchCollection MC = RG.                Matches (value); if (MC. Count > 0) {int group = MC.                    Count;                    Array = new String[group]; for (int i = 0; i < group; i++) {array[i] = Mc[i].                    Value;        }}} return array; }//<summary>//To determine if match///</summary>//&LT;PARam Name= "value" > String </param>//<param name= "regex" > Regular expression </param>///<returns>b ool</returns> public static bool Isregex (This string value, string regex) {if (Value! = Nu                ll) {Regex reg = new regex (regex); Return Reg.            IsMatch (value);            } else {return false; }        }    }}


Regular tool class notation for C # common

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.