Imports?System.Text.RegularExpressions
創(chuàng)新互聯(lián)建站是一家集網(wǎng)站建設(shè),遂昌企業(yè)網(wǎng)站建設(shè),遂昌品牌網(wǎng)站建設(shè),網(wǎng)站定制,遂昌網(wǎng)站建設(shè)報(bào)價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,遂昌網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
Public?Class?Form1
Public?Function?MadeRegexArray(ByVal?strText?As?String,?ByVal?strRegx?As?String,?ByVal?rexOpt?As?RegexOptions,?ByVal?Groups?As?Integer)?As?String()
REM?正則結(jié)果直接以字符串組形式返回
REM?strHtml待搜索的字符串
REM?strRegx正則表達(dá)式
REM?rexOpt正則選項(xiàng)
On?Error?Resume?Next
Return?MadeMatchString(MadeRegexMatch(strText,?strRegx,?rexOpt),?Groups)
End?Function
Public?Function?MadeMatchString(ByVal?mc?As?MatchCollection,?ByVal?Groups?As?Integer)?As?String()
REM?把MatchCollection以字符串組形式保存
REM?mc正則匹配的集合
REM?返回字符串組
On?Error?Resume?Next
Dim?strRegCode(mc.Count)?As?String
For?i?As?Integer?=?0?To?mc.Count?-?1
strRegCode(i)?=?mc(i).Groups(Groups).Value
Next?i
Return?strRegCode
End?Function
Public?Function?MadeRegexMatch(ByVal?strText?As?String,?ByVal?strRegex?As?String,?ByVal?rexOpt?As?RegexOptions)?As?MatchCollection
REM?獲取正則表達(dá)式匹配的集合
REM?strHtml待正則的字符串
REM?strRegex正則表達(dá)式
REM?rexOpt正則選項(xiàng)
REM?返回?MatchCollection?類型集合
On?Error?Resume?Next
Dim?rex?As?Regex?=?New?Regex(strRegex,?rexOpt)
Return?rex.Matches(strText)
End?Function
Public?Function?MadeRegexReplace(ByVal?sText?As?String,?ByVal?sRegex?As?String,?ByVal?sReplace?As?String)?As?String
REM?正則表達(dá)式文本替換
REM?sText原文本
REM?sRegex表達(dá)式
REM?sReplace替換文本
On?Error?Resume?Next
Dim?rex?As?Regex?=?New?Regex(sRegex,?RegexOptions.IgnoreCase)
Return?rex.Replace(sText,?sReplace)
End?Function
Private?Sub?Button1_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button1.Click
On?Error?Resume?Next
Dim?sRegex?As?String?=?"([\s\S]*?)"
Dim?aTable()?As?String?=?MadeRegexArray(TextBox1.Text,?sRegex,?RegexOptions.IgnoreCase,?1)
For?i?As?Integer?=?0?To?aTable.Length?-?1
TextBox2.Text?=?TextBox2.Text??aTable(i)
Next?i
End?Sub
End?Class
如圖:
正則表達(dá)式是:
/[a-zA-Z/]+$
如果要把第一個斜杠去掉,就是匹配index/index/index,用后向匹配,正則是:
(?=/)[a-zA-Z/]+$
var?reg?=?/(.{4}年.{2}月.{2}日|.{2}年.{2}月.{2}日|[^\-]{2}\-[^\-]{2}|[^\/]{2}\/[^\/]{2}|[^\\]{2}\\[^\\]{2})/g;
var?str?=?"sdfasf****年**月**日,**年**月**日,**-**,**/**,**\**asdfadf";
str.match(reg);