-
Aug 5th, 2020, 08:42 AM
#1
Help Nailing Down RegEx Pattern
I have the following text:
Code:
PR Number: 0082161694 NSN: 4820-01-606-6325 Value: $5000-10000
Issued: 10/25/19 Agency: DCSC Bid #: 16167281
SOL Number: SPE7MC20T1201 MSDS: N Critical: Y FIIG: A21100 AMC: 3Q
Item Name: (27565) VALVE,REGULATING,FL SBSA: Inspect: Destination
Quantity: 14 EA Value: $5000-10000 Return: 11/04/19 INC: 27565
Del Req: 168 Days
Description:
ITEM DESCRIPTION
VALVE,REGULATING,FL
VALVE,REGULATING,FL
RP001: DLA PACKAGING REQUIREMENTS FOR PROCUREMENT
RA001: THIS DOCUMENT
ITEM DESCRIPTION
VALVE,REGULATING,FL
VALVE,REGULATING,FL
RP001: DLA PACKAGING REQUIREMENTS FOR PROCUREMENT
RA001: THIS DOCUMENT
82796 COLTEC INDUSTRIES INC. 11916130 3 23
7PZX0 FAIRBANKS MORSE, LLC 11916130 5 23
Mfrs: 7PZX0 FAIRBANKS MORSE, LLC 11916130 10/24/19
7PZX0 FAIRBANKS MORSE, LLC PA12650465-22 10/24/19
Awards: SPE7MC18V2197/ 12/14/17 JGILS, LLC O 8 406.3100 179 days A
The specific parts that I need are highlighted above. The first highlight represents the "CageNum" whereas the second represents the "PartNum".
What makes this a little difficult is that there can be multiple rows of "Mfrs" data, but I always need the last values.
The way that I've tried getting it is to get all the text between Mfrs and Awards, but I can't seem to figure out how to get the values that I want without moving away from RegEx and start using String.Split (split by lines, get last line, split by space, get first and second to last matches).
This is what I've been going off of (fiddle):
Code:
Dim r As New Regex("(?:Mfrs:)\s(.|\s)*(?:Awards)")
But I'm sort of stumped at this point.
-
Aug 5th, 2020, 01:39 PM
#2
Re: Help Nailing Down RegEx Pattern
don't know if this is any help
took your sample from the 'fiddle'
Code:
Imports System
Imports System.Text
Imports System.Text.RegularExpressions
Module Module1
Sub Main()
Dim builder As StringBuilder = New StringBuilder()
builder.AppendLine("PR Number: 0082161694 NSN: 4820-01-606-6325 Value: $5000-10000")
builder.AppendLine(" Issued: 10/25/19 Agency: DCSC Bid #: 16167281")
builder.AppendLine("SOL Number: SPE7MC20T1201 MSDS: N Critical: Y FIIG: A21100 AMC: 3Q")
builder.AppendLine("Item Name: (27565) VALVE,REGULATING,FL SBSA: Inspect: Destination")
builder.AppendLine("Quantity: 14 EA Value: $5000-10000 Return: 11/04/19 INC: 27565")
builder.AppendLine("Del Req: 168 Days")
builder.AppendLine("Description:")
builder.AppendLine(" ITEM DESCRIPTION")
builder.AppendLine(" VALVE,REGULATING,FL")
builder.AppendLine(" VALVE,REGULATING,FL")
builder.AppendLine(" RP001: DLA PACKAGING REQUIREMENTS FOR PROCUREMENT")
builder.AppendLine(" RA001: THIS DOCUMENT")
builder.AppendLine(" ITEM DESCRIPTION")
builder.AppendLine(" VALVE,REGULATING,FL")
builder.AppendLine(" VALVE,REGULATING,FL")
builder.AppendLine(" RP001: DLA PACKAGING REQUIREMENTS FOR PROCUREMENT")
builder.AppendLine(" RA001: THIS DOCUMENT")
builder.AppendLine(" 82796 COLTEC INDUSTRIES INC. 11916130 3 23")
builder.AppendLine(" 7PZX0 FAIRBANKS MORSE, LLC 11916130 5 23")
builder.AppendLine(" Mfrs: 7PZX0 FAIRBANKS MORSE, LLC 11916130 10/24/19")
builder.AppendLine(" 7PZX0 FAIRBANKS MORSE, LLC PA12650465-22 10/24/19")
builder.AppendLine(" Awards: SPE7MC18V2197/ 12/14/17 JGILS, LLC O 8 406.3100 179 days A")
Console.WriteLine(builder.ToString())
Console.WriteLine()
Dim r As New Regex("[A-Z][A-Z][0-9]*[-][0-9]*|[0-9][A-Z][A-Z][A-Z][0-9]")
For Each Mt As Match In r.Matches(builder.ToString)
Console.WriteLine(Mt.Groups(0).Value)
Console.WriteLine(Mt.Groups(1).Value)
Next
' Console.WriteLine(r.Match(builder.ToString()))
Console.ReadKey()
End Sub
End Module
the 7PZX0 is returnd 3x times
PA12650465-22 once
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
-
Aug 5th, 2020, 02:30 PM
#3
Re: Help Nailing Down RegEx Pattern
Unfortunately I cannot match it with the pattern that is in the PartNum/CageNum (like using the hyphen) because that isn't a repeatable pattern. I suppose I will have to do the following:
- Match everything between Mfrs: and Awards
- Match every new line
- Split on double space
- Get the first and second to last match (based on double space) of the last match (based on the new line)
-
Aug 5th, 2020, 03:06 PM
#4
Re: Help Nailing Down RegEx Pattern
Maybe you can store all data between Mfrs: and Awards line by line is a list of string so the line you want is the last of the list and then parse the string you get.
question in the data between Mfrs: and Awards are all the beginning of the line the same ? in you example : "7PZX0 FAIRBANKS MORSE, LLC" are the same for the all lines.
Last edited by Delaney; Aug 5th, 2020 at 03:10 PM.
The best friend of any programmer is a search engine
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
-
Aug 5th, 2020, 04:09 PM
#5
Re: Help Nailing Down RegEx Pattern
Unfortunately it isn't. I was trying to do this using RegEx because it appears to be a pattern that RegEx could match, but my RegEx isn't strong enough to build it out. Ultimately I wound up doing what I outlined in #3 and using String.Split for the second (environment.newline) and third bullet (two spaces) points.
-
Aug 14th, 2020, 08:18 AM
#6
Hyperactive Member
Re: Help Nailing Down RegEx Pattern
Fabulous website for testing/debugging RegEx expressions...
https://regex101.com
(I have no affiliation with the website or its developers.)
-
Aug 14th, 2020, 10:52 AM
#7
Re: Help Nailing Down RegEx Pattern
Yeah, I'm familiar with the website. I personally prefer https://regexr.com, but the need behind the thread was to refine my RegEx pattern down to my exact need.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|