Share a regular expression helper

the System.Globalization the using;
the using the System.Text.RegularExpressions;


    /// <Summary>
    /// regex helper
    /// </ Summary>
    public class RegexHelper Sealed
    {
        Private RegexHelper ()
        {
        }
    
        /// <Summary>
        /// clears 'string
        /// </ Summary>
        public string CLEAN_STRING = const @ "[']";

        /// <Summary>
        whether the begin-end between the character string of authentication ///
        /// </ Summary>
        public String IS_VALID_BYTE = const @ "^ [A-Za-Z0-9] {# 0 #, # #} $. 1";

        /// <Summary>
        /// verify whether the string date
        /// </ Summary>
        public String IS_VALID_DATE = const
            @ "^ 2 \ {D}. 3 - (?: 0 [1-9] |?. 1 [0-2]) - (?: 0 [1-9? ] | [1-2] \ d | 3 [0-1]) (?: 0 [1-9] |? 1 \ d | 2 [0-3]) :( ?: 0 [1-9]? ? | [1-5] \ D) :( ?: 0 [1-9] | [1-5] \ D) $ ";

        /// <Summary>
        /// verify decimal string
        /// </ Summary>
        public string IS_VALID_DECIMAL = const @. "[0] \ D {1,2} | [. 1]";

        /// <Summary>
        /// authentication string is for EMAIL
        /// </ Summary>
        IS_VALID_EMAIL = const String public
            @ "^ ([\ W -. \] +).. @ ((\ [[0-9] l, 3} {\ [0-9] l, 3} {\ [0- 9] {1,3} \) | . (. ([\ w -] + \) +)) ([a-zA-Z] {2,4} | [0-9] {1,3}) (? \]) $ ";

        /// <the Summary>
        /// string verify whether the IP
        /// </ Summary>
        public String IS_VALID_IP = const
            @ "^ (\ D {1,2} |. 1 \ D \ D | 2 [0-4] \ D | 25 [0-5]) \ (\. d {1,2} | 1 \ d \ d | 2 [0-4] \ d | 25 [0-5]) \ (\ d {1,2} |. 1 \ d \ d | 2 [0- .. 4] \ D | 25 [0-5]) \ (\ D {1,2} |. 1 \ D \ D | 2 [0-4] \ D | 25 [0-5]) $ ";

        // / <Summary>
        /// verify whether the string name suffix
        /// </ Summary>
        public string IS_VALID_POSTFIX = const @:; "\ (I {0}?) $."

        /// <Summary>
        /// verify that the telephone number string is
        /// </ Summary>
        public string IS_VALID_TEL = const @ "(\ D + -) (\. 4 {D} - \ D}. 7 {|??? \ {D}. 3 - \ D ?. 8 {} | ^ \ D {7, 8}) (- \ + D) ";

        /// <Summary>
        /// string to verify the URL
        /// </ Summary>
        public const string IS_VALID_URL = @ "^ [a-zA-z] +: // (\\ w + (- \\ w +) *) (\\ (\\ w + (- \\ w +) *).) * ( ? \\ \\ S *) $? ";

        #region replacement string
        /// <Summary>
        /// replacement string
        /// </ Summary>
        /// <param name =" iNPUT "> input string </ param>
        /// <param name = "REGEX"> regular expression </ param>
        /// <Returns> after replacing the string </ Returns>
        public static string ReplaceInput (INPUT string, string REGEX)
        {
            return the Regex .replace (INPUT, REGEX, string.Empty);
        }

        /// <Summary>
        /// replacement string
        /// </ summary>
        /// <param name = "input" > input string </ param>
        /// <param name = "regex" > regular expression </ param>
        /// <param name = "Replace"> replacement string </ param>
        /// <Returns> After replacing the string </ returns>
        ReplaceInput static string public (INPUT string, string REGEX, Replace string)
        {
            return the Regex.Replace (INPUT, REGEX, Replace);
        }

        #endregion

        #region authentication string

        /// <Summary>
        /// verification string
        /// </ Summary>
        /// <param name = "iNPUT"> input string </ param>
        /// <param name = "REGEX"> regular expression </ param>
        /// <Returns> verify by < /returns>
        public static bool CheckInput(string input, string regex)
        {
            Return Regex.IsMatch (INPUT, REGEX);
        }

        #endregion

        #region conventional method

        /// <Summary>
        /// authentication string
        /// </ Summary>
        /// <param name = "INPUT"> input character string </ param>
        /// <param name = "REGEX"> regular expression </ param>
        /// <param name = "the begin"> start digital </ param>
        /// <param name = "End" > end digital </ param>
        /// <Returns> verify by </ Returns>
        public static BOOL ValidByte (INPUT String, String REGEX, the begin int, int end)
        {
            BOOL RET = to false;
            if (!string.IsNullOrEmpty(regex))
            {
                String Regex.Replace REP = ( "# 0 #", begin.ToString (the CultureInfo.InvariantCulture));
                REP = rep.Replace ( "# #. 1", end.ToString (the CultureInfo.InvariantCulture));
                RET = CheckInput ( iNPUT, REP);
            }
            return RET;
        }

        /// <Summary>
        /// authentication string
        /// </ Summary>
        /// <param name = "iNPUT"> input string </ param>
        /// <param name = "regex"> regular expression </ param>
        /// <param name = "FIX"> extension </ param>
        /// <Returns> verify by </ returns>
        public static bool ValidPostfix(string input, string regex, string fix)
        {
            string ret = string.Format(CultureInfo.InvariantCulture, regex, fix);
            return CheckInput(input, ret);
        }

        #endregion

        
    }


Reproduced in: https: //www.cnblogs.com/kevinGao/archive/2012/01/15/2323338.html

Guess you like

Origin blog.csdn.net/weixin_34050519/article/details/93359074