Solved

Pulling 5 digit numeric values out of SQL surrounded by `

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now