Solved

Pulling 5 digit numeric values out of SQL surrounded by `

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 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