Why doesn't this regular expression work?

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
 
J

Jim Hollenhorst

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
 
C

Chris W.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top