We help IT Professionals succeed at work.

Regular Expression Not working in VB.net

BobBarker_99
BobBarker_99 asked
on
Medium Priority
163 Views
Last Modified: 2012-05-07
I have posted my code below.
When I use the regex below, along with the text I define in "body", it works when I try it online at http://gskinner.com/RegExr/

VB.net doesnt find any matches though.

can anyone tell me what I need to do so that this regex will work in vb?
Dim body As String = "Customer Information:" & vbNewLine & "Bob Jones" & vbNewLine & "Phone: 442-493-2935"
 
Dim reg3 As New System.Text.RegularExpressions.Regex("(?<=customer information|customer information:)\s*\w*\s\w*", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
        matches = reg.Matches(body)
        If matches.Count > 0 Then
            Dim result As String = matches(0).Value.Trim(" ")
             Return result
        End If

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
The following returns the matched text. The ^\r at the end will prevent the last carriage return from being picked up. You can use ^\n, but you will get a carriage return character in your match.
(?<=Customer Information:)\s*[^\n]*\n[^\r]*

Open in new window

CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
The above is assuming you have a newline after your phone number in regards to capturing the carriage return.
Top Expert 2013
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Wow I'm very slow today.  It was just a typo (reg vs reg3)!!!

Author

Commented:
I am an idiot
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.