Introduction to the Regex class for C # regular expressions

Source: Internet
Author: User

First, in C #, to use the regular expression class, add the following statement at the beginning of the source file:

using System.Text.RegularExpressions;

Second, the Regex class commonly used methods

1. Static Match method

Using the static Match method, you can get a continuous substring of the first matching pattern in the source.

the static Match method has 2 overloads, each of which is

Regex.match (string input, string pattern);

regex.match (string input, string pattern, regexoptions options);

parameter representation of the first Overload: input, Mode

The second overloaded parameter is represented by a bitwise OR combination of the input, pattern, RegexOptions enumeration.

The valid values for the RegexOptions enumeration are:

Complied means compiling this pattern

Cultureinvariant says no cultural background is considered

ECMAScript to ECMAScript, this value can only be used in conjunction with ignorecase, Multiline, complied

Explicitcapture indicates that only explicitly named groups are saved

IgnoreCase indicates an input-insensitive case

Ignorepatternwhitespace indicates that the non-escaped whitespace in the pattern is removed and the note marked by the # is enabled

Multiline represents multiline mode, which alters the meaning of metacharacters ^ and $, and they can match the beginning and end of a line

None means no setting, this enumeration item has no meaning

RightToLeft represents right-to-left scanning, matching, at which point the static match method returns a right-to-left first match

Singleline represents a single-line pattern that alters metacharacters. meaning that it can match newline characters

Note: Multiline can be used with Singleline without ECMAScript. Singleline and Multiline are not mutually exclusive, but mutually exclusive with ECMAScript.

2. Static Matches method

The overloaded form of this method is the same as the static Match method, which returns a matchcollection that represents the matching set of patterns in the input.

3. Static IsMatch method

This method returns a bool, overloaded form with static matches, if the input matches the pattern, returns true, otherwise false is returned.

Can be understood as: IsMatch method, returns whether the collection returned by the matches method is empty.

Introduction to the Regex class for C # regular expressions

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.