vb.net正则替换 vb 正则
vb.net正则表达式
Imports System.Text.RegularExpressions
创新互联公司2013年成立,是专业互联网技术服务公司,拥有项目网站设计制作、网站设计网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元阳明做网站,已为上家服务,为阳明各地企业和个人服务,联系电话:18980820575
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
如图:
vb.net正则表达式 替换内容
@interface不替换的话,就把正则改成:
@(?!interface)[^\s]+(\s|$)
如果@t3(synopsis = "AB") 这个等号前后没有空格,就很简单,直接用下面的搞定,如果有空格,这个正则就会复杂很多了:
Regex.Replace(@"@t1
@t2()
@t3(synopsis=""AB"")
@t4(""unused"")
creatCommChat(@WebParam(name=""chatID"") String chatID,@WebParam(name=""creatUserID"") String creatUserID)", @"@[^\s]+(\s|$)", "")
VB.NET用正则表达提取数字的问题!
你把替换所有非数字为空字符串,改为替换所有非数字为空格,就可以把每组数字分开了.
完整的程序如下(改动的地方见注释)
Dim bbb As String
bbb = TextBox1.Text
Dim My_str As String = Regex.Replace(bbb, "[^0-9]", " ") '这里把替换所有非数字为空字符串,改为替换所有非数字为空格
MsgBox(My_str)
vb.net正则表达式的写法
var reg = /;SPLIT(?:(?!;SPLIT)[\s\S])*;SPLIT/g;
var str = "";
str.replace(reg,"");
分享名称:vb.net正则替换 vb 正则
路径分享:http://scyanting.com/article/hpdjed.html