正則運算的問題
问题如下:
字符串:
"plum * pear * BALL"
要将以上字符串转成下面的正则
regex :
plum & ".*" pear & ".*" BALL
.*代表的是任何字符
做这样的正则我的应用是用来搜索匹配类似下面的集合
plum IS pear ON BALL
plum ARE pear ON BALL
下面是我目前写的代码
Public Sub main6() Dim regex As Regex = New Regex(" ") ' Split on hyphens. Dim substrings() As String = regex.Split("plum * pear * BALL") Dim c As String = vbNullString For Each match As String In substrings If match = "*" Then match = "'.*'" End If 'Me.RichTextBox1.Text += match & vbCrLf c += match & " & " Next Dim c1 As String = c.Trim(" ") c1 = c1.Trim("&") c1 = c1.Trim(" ") Dim regex1 As Regex = New Regex(c1) Me.RichTextBox1.Text = c1 End Sub New Regex(plum & '.*' pear & '.*' BALL)