ASP Regex匹配字串提取

來源:互聯網
上載者:User

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.