C # Regular Expressions Learn 1-regex classes, RegexOptions and Regex class constructors

Source: Internet
Author: User

Using regular expressions in C #, the first step is to introduce the using System.Text.RegularExpressions namespace, which includes the following eight classes:
The Regex-----contains regular expressions and methods that use regular expressions
The matchcollection----contains all Bibi items found by a regular expression
The Match-----contains the text of all Bibi in a Bibi entry
Gropcollection---Contains all the groupings in a Bibi
The group-----contains details of a grouping in a grouped collection
CaptureCollection---Contains all the capture objects for a group
Capture-----Returns a string that captures the Bibi
Regexcompalationinfo----provides all the details needed to compile a regex into a program
The most important class in the above eight classes is the Regex class, which not only creates regular expressions, but also uses regular expressions to control the action string in many ways. Many of its methods are static and there is no need to define objects just once.

The first thing to say in the Regex class is a variable regexoptions of an enumerated type, which controls the properties that the Regex method performs, and by default, case sensitive, reading data from left to right
For example: Regex.ismacth (mystring, "abc", regexoptions.ignocase| Regexoptiongs.righttoleft);
Related options:
Ignocase Ignore case
RightToLeft read from right to left
None without any flags
MultiLIne ^ and $ can match the beginning and end of the line and string
Singleline Specify special characters "." can match any character except line breaks

Two main constructors of the Regex class:
1, Regex (string pattern);
2. Regex (strign pattern,regexoptions option)

The first parameter is to establish a regular expression such as:
protected void Page_Load (object sender, EventArgs e)
{
Regex myrx = new Regex ("abc");
Response.Write (Myrx. IsMatch ("ABC is OK"));
}

If you want to Bibi the case ABC, you can use the RegexOptions option flag
Note: The Bibi object of the regex is ASCII text

Related Article

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.