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