ASP Regular Expression matching string Extraction

Source: Internet
Author: User

ASP regular expression, found on the InternetArticleBoth are reproduced in the same copy, and only the replacement is described. There is no description of how to extract the required string. Here is an example.

The reason was that a csdn user asked how to extract the meta character set, so he thought about it.

Key points:

1. Whether the matches object matches

Use the Count attribute. If the value is greater than 0, it indicates that the Count attribute is matched.

2. submatches extracts the key attribute of the string to be matched as an array.

If the extracted part (the Part indexed by the signature number) is one, the index 0 is obtained. For example:

 
Matches (0). submatches (0)

If multiple indexes are obtained, the index is pushed accordingly.

3. The double quotation mark escape in ASP uses two consecutive double quotation marks "", which is similar to the single quotation mark escape in database queries. For example:

To define the following expression:

<Meta charset = "UTF-8"/>

After escaping:

 
STR = "<meta charset =" "UTF-8"/>"

<Script language = "VBScript"> dim STR, re, rvstr = "<meta http-equiv = Content-Type content = text/html; charset = gb2312> "str =" <meta http-equiv = Content-Type content = "" text/html; charset = gb2312 ""> "str =" <meta http-equiv = Content-Type content = "" text/html; charset = gb2312 ""/> "str =" <meta http-equiv = Content-Type content = 'text/html; charset = gb2312 '/> "str =" <meta charset = "" UTF-8 "/>" set Re = new regexpre. patter N = "<meta [^>] + charset = [" "]? ([\ W \-] +) [^>] *> "re. global = truere. ignorecase = truere. multiline = trueset matches = Re. execute (STR) If matches. count> 0 thenmsgbox matches (0 ). submatches (0) end if </SCRIPT>

ASP Regular Expression reference:

Http://vod.sjtu.edu.cn/help/Article_Show.asp? ArticleID = 2124 & articlepage = 2

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.