Several issues that should be paid attention to in the RegEx. Match Method

Source: Internet
Author: User
I. Overview

RegEx. Match Method

Search for matching items of the regular expression in the input string, and return the exact result as a single match object.

Reload list
(1) Search for the regular expression match specified in the RegEx constructor in the specified input string.

[C #] public match (string );

(2) Search for regular expression matching items in the input string from the starting position of the specified input string.

[C #] public match (string, INT );

(3) search the regular expression match provided by the pattern parameter in the specified input string.

[C #] public static match (string, string );

(4) Search for a regular expression match with the length of the specified input string from the start position of the specified input string.

[C #] public match (string, Int, INT );

(5) Search for the matching items of the regular expression provided by the pattern parameter in the input string (the matching options are provided in the options parameter ).

[C #] public static match (string, String, regexoptions );

  II. Application Example

1. the following code is used to retrieve the title attribute in the webpage.

Match titlematch = RegEx. Match (filecontents, "<title> ([^ <] *) </title>", regexoptions. ignorecase | regexoptions. multiline );

Filetitle = titlematch. Groups [1]. value;

Note that the groups index obtained by the Red 1 and RegEx. Match Method starts from 1 instead of 0.

2. The following code is used to retrieve the "content" attribute of the webpage header.

Match descriptionmatch = RegEx. match (filecontents, "<meta name =/" Description/"content =/" ([^ <] *)/">", regexoptions. ignorecase | regexoptions. multiline );
Filedesc = descriptionmatch. Groups [1]. value;

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.