Can someone help me with a file search filter Using Regex in C# Windows Form Application

I'm trying to get the op numbers from the following filename strings using RexEx which the pattern will be used in VS2017 using the C# language for developing a Windows Form Application. In this application, we are filtering filenames in a datagridview by Op number when searching through a folder directory and all its subdirectories. I'm having an issue trying to get the regex to work on the tester websites I have tried. These are regxr.com and regexstorm.net/tester

Filename1: C-2590-3 REV-B OP#50.pcl
Filename 2: C-2590-3 REV-B OP#50-59.pcl
Filename 3: C-2590-3 REV-B OP#50-59-90.pcl
Filename 4: C-2590-3 REV-B OP#50-59-90-70(Flip).pcl
Filename 5: C-2590-3 REV-B OP#50-59-90 (Flip)60-90.pcl

The text I need to capture is :

Filename 1 Results: 50
Filename 2 Results: 50-59
Filename 3 Results: 50-59-90
Filename 4 Results: 50-59-90-70
Filename 5 Results: 50-59-90 60-90

This is what I have tried on the regexr.com tester:

(?<=\043)\d{2}|(?<=\043)\d{2}.\d{2}|(?<=\043)\d{2}.\d{2}.\d{2}

(?<=#)\d{2,}|(?<=#)\d{2,}.\d{2,}|(?<=#)\d{2,}.\d{2,}.\d{2,}

and I keep getting stuck because it will only show me the 1st two digits "50"

I'm not real familiar with Regex and I thought I should get some help because I'm missing something And don't know what that might be.

Can anyone help with this? Here is a screenshot of the form application running.

Tesa File Search - Screenshot1
LVL 1
Steve WilliamsProduct Design EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
You don't really need the lookbehinds--simple capture groups should suffice.

(Filename)\s*(\d+).*OP#(\d+(?:-\d+)*)(?:\s*\(Flip\)(\d+(?:-\d+)*))?.*

Open in new window


The pattern explanation is broken down here on the "Explain" tab:  https://regexr.com/40ita

You can also look at the "Replace" tab to see the results as you have listed.
0
Steve WilliamsProduct Design EngineerAuthor Commented:
@käµfm³d
I may have not explained this correctly. I need only the following returned so I can populate the datatable row, each line below is a different row in the datatable:

50
50-59
50-59-90
50-59-90-70
50-59-90 60-90
0
käµfm³d 👽Commented:
Then you can simply grab capture groups 3 and 4, where group 4 is sometimes empty.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Steve WilliamsProduct Design EngineerAuthor Commented:
Thanks for your help! But this did not work out how I planned but after playing with your regex solution I realized that the different variations of file name structures could not be done with regex. The end users try to follow a format but rarely do. I do know that they always use the OP# in the string and the file name ends with .pcl or .sch so this is my final expression.

#(.*?)\.

It finds everything between the "#" sign and the "."
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.