C # language Regular usage

Source: Internet
Author: User

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

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: info-contact@alibabacloud.com 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.