[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Regular Expression Not working in VB.net

Posted on 2009-07-06
5
Medium Priority
?
151 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24787318
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 75

Expert Comment

by:käµfm³d 👽
ID: 24787326
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 2000 total points
ID: 24787339
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
ID: 24787362
Wow I'm very slow today.  It was just a typo (reg vs reg3)!!!
0
 

Author Closing Comment

by:BobBarker_99
ID: 31600258
I am an idiot
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

650 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