重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
在所给代码基础上仅作修改.
创新互联建站是网站建设专家,致力于互联网品牌建设与网络营销,专业领域包括网站设计制作、做网站、电商网站制作开发、成都微信小程序、微信营销、系统平台开发,与其他网站设计及系统开发公司不同,我们的整合解决方案结合了恒基网络品牌建设经验和互联网整合营销的理念,并将策略和执行紧密结合,且不断评估并优化我们的方案,为客户提供全方位的互联网品牌整合方案!
首先导入命名空间
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 正则结果直接以字符串组形式返回
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/]+$
这种情况不建议使用正则做匹配,而且从你贴出来的这一小部分代码里也看不出什么规律。
建议使用 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.*)"