Solved

Regular Expression Not working in VB.net

Posted on 2009-07-06
5
146 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

0
Comment
Question by:BobBarker_99
  • 2
  • 2
5 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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

0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
The above is assuming you have a newline after your phone number in regards to capturing the carriage return.
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
Comment Utility
just wondering if there is any typo:
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)

You are declaring 'reg3' and then calling 'reg'.Matches
shouldn't that be matches = reg3.Matches(body)
0
 

Author Comment

by:BobBarker_99
Comment Utility
Wow I'm very slow today.  It was just a typo (reg vs reg3)!!!
0
 

Author Closing Comment

by:BobBarker_99
Comment Utility
I am an idiot
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now