ASP Regex,網上搜到的文章都是轉載的同一份,且只說明了替換,沒有說明怎麼提取需要的字串,這裡給出一個例子.
起因是一個CSDN網友問起怎麼提取meta的字元集,自己便琢磨了一下.
幾個要點:
1.Matches對象 是否匹配到
使用Count屬性,若>0則表示匹配到了
2.SubMatches 提取要匹配字串的關鍵屬性,為一數組
若提取的部分(挎號所挎的部分)為一個,則取索引0,例如:
matches(0).SubMatches(0)
若取多個,則索引依此類推.
3. ASP中雙引號轉義使用兩個連續的雙引號"",和資料庫查詢中的單引號轉義有點類似,例如:
要定義下面的運算式:
<meta charset="UTF-8"/>
使用轉義後:
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.Pattern = "<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 Regex參考:
http://vod.sjtu.edu.cn/help/Article_Show.asp?ArticleID=2124&ArticlePage=2