?
Solved

Regular Expression Not working in VB.net

Posted on 2009-07-06
5
Medium Priority
?
150 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month12 days, 21 hours left to enroll

777 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