在所給代碼基礎(chǔ)上僅作修改.
創(chuàng)新互聯(lián)建站是網(wǎng)站建設(shè)專家,致力于互聯(lián)網(wǎng)品牌建設(shè)與網(wǎng)絡(luò)營銷,專業(yè)領(lǐng)域包括網(wǎng)站設(shè)計制作、做網(wǎng)站、電商網(wǎng)站制作開發(fā)、成都微信小程序、微信營銷、系統(tǒng)平臺開發(fā),與其他網(wǎng)站設(shè)計及系統(tǒng)開發(fā)公司不同,我們的整合解決方案結(jié)合了恒基網(wǎng)絡(luò)品牌建設(shè)經(jīng)驗和互聯(lián)網(wǎng)整合營銷的理念,并將策略和執(zhí)行緊密結(jié)合,且不斷評估并優(yōu)化我們的方案,為客戶提供全方位的互聯(lián)網(wǎng)品牌整合方案!
首先導(dǎo)入命名空間
Imports System.Text.RegularExpressions
然后:
Function geta(ByVal Str)
Dim re As New Regex("a(.+?)href=""*([^\s]+?)""*(\s|)")
Dim Contents As MatchCollection = re.Matches(Str)
Dim links As String = Nothing
For Each Match In Contents ' 遍歷匹配集合。
links = links + Match.SubMatches(1) + "|"
Next
geta = Mid(links, 1, Len(links) - 1)
geta = Replace(geta, "'", "")
re = Nothing
End Function
Imports?System.Text.RegularExpressions
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正則表達式
REM?rexOpt正則選項
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?獲取正則表達式匹配的集合
REM?strHtml待正則的字符串
REM?strRegex正則表達式
REM?rexOpt正則選項
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?正則表達式文本替換
REM?sText原文本
REM?sRegex表達式
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
如圖:
var reg = /;SPLIT(?:(?!;SPLIT)[\s\S])*;SPLIT/g;
var str = "";
str.replace(reg,"");
正則表達式是:
/[a-zA-Z/]+$
如果要把第一個斜杠去掉,就是匹配index/index/index,用后向匹配,正則是:
(?=/)[a-zA-Z/]+$
這種情況不建議使用正則做匹配,而且從你貼出來的這一小部分代碼里也看不出什么規(guī)律。
建議使用 HtmlAgilityPack 或者 NSoup 一類的庫,就可以把 HTML 文檔變成類似于 jQuery 選擇的方式來處理了,容錯性和便捷度都更高。
Imports System.Text.RegularExpressions '引入命名空間
dim isTrue as boolean = regex.Match(textbox1.text, _
"(.*\x22.*\x22.*)|(.*\x27.*\x27.*)").Success
' 可匹配形如:"5648ffq" ,'454564565', 35235"ere"333, 434'ppp'89eru 等
'如果要匹配中文的“”、‘’
'改為:"(.*\u201C.*\u201D.*)|(.*\u2018.*\u2019.*)"