Use of the Regex class.

Source: Internet
Author: User

the Regex class includes methods such as IsMatch, Match, matches, Replace, and Split . If you use the ^ and $ enclosing tags, it indicates that the entire string (not just the substring) must match the regular expression.

The 1.Match method matches the string .
string input = "test@sina.com"; Input string to match
String Patten = @ "[a-za-z]+@[a-za-z]+/.com$"; Regular expressions
Regex r = new Regex (patten); Declaring a Regex object
Match m = r.match (input); Match using the Match method
if (m.success)//loops output all matching substrings

{
return true;
}
Else
{
return false;
}

Regular Expression Symbol

/b matches a word boundary, refers to the position between the word and the space
/b matches non word boundaries
/d matches a numeric character, equivalent to [0-9]
/d matches a non-numeric character, equivalent to [^0-9]
/F matches a page feed character
/n matches a line feed
/R matches a return character
/s matches any white space characters, including spaces, tabs, page breaks, and so on
+ Match one or more of the previous child expressions

Note When using the transfer character "/", you need to precede the string with the "@" symbol for example:

String mystr= "ddd AAA ddd SS";
Regex r = new Regex (@ "/s+", regexoptions.singleline);

String outname = R.replace (MyStr, ",");

Outname will output: DDDAAADDDSS;

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.