Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Pulling 5 digit numeric values out of SQL surrounded by `

Posted on 2013-12-03
4
Medium Priority
?
207 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
[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
  • 3
4 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 2000 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

604 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