What are the common regular expressions in C #
This article is about what regular expressions are commonly used in C#. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Summary description of using System; using System.Text.RegularExpressions; namespace CommonTools {/ * * / RegexLib. / public class RegexLib {/ / verify the Email address public static bool IsValidEmail (string strIn) {/ / Return true if strIn is in valid e-mail format. Return Regex.IsMatch (strIn, @ "^ ([\ w -\] +) @ (\ [[0-9] {1pr 3}\. [0-9] {1pr 3}\.) | (([\ w -] +\.) +)) ([a-zA-Z] {2} 4} | [0-9] {1pr 3}) (\]) $");} / / the date form of dd-mm-yy instead of mm/dd/yy. Public static string MDYToDMY (String input) {return Regex.Replace (input, "\\ b (?\ d {1Magne2}) / (?\ d {1Power2}) / (?\ d {2year 4})\ b", "${day}-${month}-${year}");} / / verify whether it is a decimal public static bool IsValidDecimal (string strIn) {return Regex.IsMatch (strIn,@ "[0].\ d {1pm 2} | [1]"). } / / verify whether it is the phone number public static bool IsValidTel (string strIn) {return Regex.IsMatch (strIn,@ "(\ dwatch -)? (\ d {4} -?\ d {7} |\ d {3} -?\ d {8} | ^\ d {7pr 8}) (-\ d +)?) } / / verify public static bool IsValidDate (string strIn) {return Regex.IsMatch (strIn) @ "^ 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)") } / / verify that the suffix name public static bool IsValidPostfix (string strIn) {return Regex.IsMatch (strIn,@ "\. (? i:gif | jpg) $");} / / verify that the character is between 4 and 12 public static bool IsValidByte (string strIn) {return Regex.IsMatch (strIn,@ "^ [a Mizz] {4jue 12} $") } / / verify IP public static bool IsValidIp (string strIn) {return Regex.IsMatch (strIn) @ "^ (\ d {1Magne2} | 1\ d\ d | 2 [0-4]\ d | 25 [0-5])\. (\ d {1-4]\ d | 2 [0-4]\ d | 25 [0-5])\. (\ d {1-4]\ d | 2 [0-4])\ d | 25 [0-5])\. (\ d {1} 2} | 1\ d\ d | 2 [0-4]\ d | 25 [0-5] $") } Thank you for reading! This is the end of this article on "what regular expressions are commonly used in C#". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!