Solved

Pulling 5 digit numeric values out of SQL surrounded by `

Posted on 2013-12-03
4
200 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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 …
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

776 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