大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
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
如图:
正则表达式是:
/[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);