有下面几个字符串"01 White"
"02 White"
"03 Color White"
"04 Color White"
"05 Black"
"06 Blue"我要取出含有White但又没有Color一词的行,请问正则表达式怎么写也就是说在上面中能返回前两行.
"02 White"
"03 Color White"
"04 Color White"
"05 Black"
"06 Blue"我要取出含有White但又没有Color一词的行,请问正则表达式怎么写也就是说在上面中能返回前两行.
然后再把特殊字符换成Color White
仅匹配数字空格后面的White或者零宽度负预测先行断言。仅当子表达式不在此位置的右侧匹配时才继续匹配。
例如,\b(?!Color\s+)White\b 与不以 Color 开头的 White 匹配。
s = "01 White" & vbCrLf & _
"02 White" & vbCrLf & _
"03 Color White" & vbCrLf & _
"04 Color White" & vbCrLf & _
"05 Black" & vbCrLf & _
"06 Blue"
Dim re As New RegExp
Dim sh
re.Global = True
re.Pattern = "(\d){2}\sWhite"
Set sh = re.Execute(s)
For Each h In sh
MsgBox h
Next
End Sub
Private Sub Form_Load()
Dim s(5) As String, i As Byte
s(0) = "01 White"
s(1) = "02 White"
s(2) = "03 Color White"
s(3) = "04 Color White"
s(4) = "05 Black"
s(5) = "06 Blue"For i = 0 To 5
If InStr(s(i), "White") And InStr(s(i), "Color White") = 0 Then Debug.Print s(i)
Next
End Sub
另问一下:五楼的回复中
re.Global = True
re.Pattern = "(\d){2}\sWhite"
正则的使用为什么要带“”???