Solved

Regular Expression Not working in VB.net

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

717 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