十年網(wǎng)站開(kāi)發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營(yíng)維護(hù)+專(zhuān)業(yè)推廣+無(wú)憂售后,網(wǎng)站問(wèn)題一站解決
Imports?System.Text.RegularExpressions
創(chuàng)新互聯(lián)從2013年成立,是專(zhuān)業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目網(wǎng)站設(shè)計(jì)、做網(wǎng)站網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元房山做網(wǎng)站,已為上家服務(wù),為房山各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:13518219792
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?類(lèi)型集合
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
如圖:
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.*)"
var reg = /;SPLIT(?:(?!;SPLIT)[\s\S])*;SPLIT/g;
var str = "";
str.replace(reg,"");
這種情況不建議使用正則做匹配,而且從你貼出來(lái)的這一小部分代碼里也看不出什么規(guī)律。
建議使用 HtmlAgilityPack 或者 NSoup 一類(lèi)的庫(kù),就可以把 HTML 文檔變成類(lèi)似于 jQuery 選擇的方式來(lái)處理了,容錯(cuò)性和便捷度都更高。
正則表達(dá)式是:
/[a-zA-Z/]+$
如果要把第一個(gè)斜杠去掉,就是匹配index/index/index,用后向匹配,正則是:
(?=/)[a-zA-Z/]+$
在所給代碼基礎(chǔ)上僅作修改.
首先導(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