Why doesn't this regular expression work?

  • Thread starter Thread starter Chris W.
  • Start date Start date
C

Chris W.

I'm having a problem and it's driving me crazy. This code does
not work when run under VB.NET, but it works in 2 regular expression
evaluators. Am I missing something here?

Chris

-----------

Sub test()
Dim testString As String = "Me.Button1.Name = 'Button1'"
Dim regVars As New Regex( _
"(?:^\s*)(?<name>.*)\s*=\s*(?<value>.*)(?=\r\n)", _
RegexOptions.IgnoreCase _
Or RegexOptions.Multiline _
Or RegexOptions.Compiled _
)
Dim regMC As MatchCollection = regVars.Matches(testString)
If regMC.Count > 0 Then
MsgBox("Success")
End If
End Sub
 
Chris,

I think your problem is that you are searching for the line termination
characters and don't have them in your test string, but do have them in the
text box you are using to test the expression (using Expresso?). Try
changing the second line of your code to:

Dim testString As String = "Me.Button1.Name = 'Button1'" & vbCrLf

Jim
 
Chris,

I think your problem is that you are searching for the line termination
characters and don't have them in your test string, but do have them in the
text box you are using to test the expression (using Expresso?). Try
changing the second line of your code to:

Dim testString As String = "Me.Button1.Name = 'Button1'" & vbCrLf

Jim

That was it Jim, thanks! :-)) I figured it had to be something fairly
simple!

Chris
 
Back
Top