Solved

Pulling 5 digit numeric values out of SQL surrounded by `

Posted on 2013-12-03
4
202 Views
Last Modified: 2013-12-03
I have a request to parse a long and complex SQL query and pull out the 5 digit ID's.  I found a method here:

stackoverflow.com/questions/7927871/find-a-set-of-numbes-in-long-string-using-regex

Which appears to do what I need it to do but I can't get it to work.  It's not finding any row's at the "For Each" statement or atleast is not entering there...  Any assistance would be greatly appreciated!
Imports System.Globalization
Imports System.IO
Imports System.Windows.Forms
Imports System.Text.RegularExpressions
Imports System.Collections.Generic

Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        ProcessFile()
    End Sub

    Private Sub ProcessFile()
        Dim MyMatches As MatchCollection
        Dim MyRegex As New System.Text.RegularExpressions.Regex("^\d{5}$")

        MyMatches = MyRegex.Matches(txtEntry.Text.ToString)

        For Each Row As Match In MyMatches
            Console.WriteLine(Row.Value)
        Next
    End Sub
End Class

Open in new window


This is a sample of the SQL I'm trying to parse (The SQL I'm parsing is very long and complex I've simplified this example):
SELECT * FROM TBL A INNER JOIN TBL2 S
ON A.SVC_ID = S.SVC_ID 
AND SVC_ID IN ('24223','27048','53075','59019');

Open in new window


Ultimately I would like to output the findings to a second multiline textbox on my form.
0
Comment
Question by:EDW_Gideon
  • 3
4 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 39693875
The pattern you're using ("^\d{5}$") should possibly be changed to "(?<!\d)\d{5}(?!\d)"

See if that helps
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39693881
The reason being that ^ and $ match the start and end of the string, respectively. In your case, the numbers are not at the start or end of the string.
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39693884
I'm hoping that negative-lookbehinds and negative-lookaheads will work. If not, then this may work, but it will also match the first 5 digits of numbers with more than 5 digits: "\d{5}"
0
 

Author Closing Comment

by:EDW_Gideon
ID: 39693914
FANTASTIC!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual studio 2015 1 34
Name Space error VS2015 1 35
vb.net convert long time to mm:ss 23 20
Consume a webservice via VB in Visual Studio 2015 3 12
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.

685 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