string phone = "";
String pattern @ "|\d{10}";
BOOL Rusurt = false;
Console.WriteLine ("Please enter phone number");
do{
Phone = Console.ReadLine ();
Rusurt = Rogex.ismatch (Phone,pattern);
Phone is the mobile number, pattern regular expression
if (!result)
Console.WriteLine ("Badnum,try Again");
}
while (!result)
Console.WriteLine ("Good");
Regular case studies:
static void Main (string[] args) {regex reg1 = new Regex (@ "\d+"); String str = REG1. Replace ("123", "INSERT into table where id = $&"); Console.WriteLine (str); Output insert into table where id = 123 Regex reg2 = new Regex (@ "1\+1= (\d)"); String str2 = Reg2. Replace ("1+1=3", "not $ $"); Console.WriteLine (STR2); The output is not 3 regex reg3 = new Regex (@ "1\+1= (? <result>\d)"); String str3 = Reg3. Replace ("1+1=3", "Not ${result}"); Console.WriteLine (STR3); Output is not 3 regex reg4 = new Regex (@ "\d+"); String STR4 = Reg4. Replace ("123ABC", "Behind $ '"); Text after matching text Console.WriteLine (STR4); The output is followed by abcabc why is the output followed by ABCABC? Because $ ' means ABC, then replace 123 in the original string. Do not know how many times this sentence regex reg5 = new Regex (@ "\d+"); String STR5 = Reg5. Replace ("ABC123", "Front is $ '"); ABC Front is the ABC symbol is 1 left that Console.WriteLine (STR5); Regex reg6 = new Regex (@ "\d+"); String STR6 = Reg6. Replace ("ABC123", "right raw input string $_"); Console.WriteLine (STR6); The output to the right is the original string ABC123 Console.readkey (); }
C # language Regular usage