Vexing regex in VB, Pt. 2

I need to find table names that are located between two markers, "Begin InputTables" and "Begin OutputColumns". The table names are in turn located between double quotes. In the following example, I am looking for "AGCOUNTY", "ELIGIBILITY" and "X":

Begin InputTables
    Name ="AGCOUNTY"
    Name ="ELIGIBILITY"
    Name ="X"
End
Begin OutputColumns
Since I'm looping through the text, I don't need or want to find these strings use a regex MatchCollection.

My question: why doesn't the following regex...

(?<=^Begin InputTables\r*.*)X
... find the X in singleline mode?

This regex...

(?<=^Begin InputTables\r\n.*)AGCOUNTY
... will find AGCOUNTY in multiline mode, and this regex...

(?<=^Begin InputTables\r\n.*\r\n.*)ELIGIBILITY
... will find ELIGIBILITY in multiline mode.

Put another way, what regex can I use to place an unknown number of carriage returns in a lookahead in .Net?
aanuncioAsked:
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.

Terry WoodsIT GuruCommented:
It worked for me on myregextester.com with the .NET mode turned on. The wildcard "." should match \r so the pattern can be simplified to:
(?<=^Begin InputTables.*)X

Open in new window

but it won't work if the word Begin is not at the very start of the input text, which is the only thing that ^ matches.
0
Terry WoodsIT GuruCommented:
Are you wanting to find those 3 tables by their exact names, or would you prefer to grab the values matching something like:
Name ="[^"]*"

Open in new window

0
Terry WoodsIT GuruCommented:
Multiline mode will make ^ match the beginning of any line, rather than just the beginning of the input string.
0
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Terry WoodsIT GuruCommented:
\s matches a space character, which can be a space, tab, newline or line feed. That might be what you're looking for?
0
ozoCommented:
.
0
Terry WoodsIT GuruCommented:
This pattern might do the trick? It will capture the table names; you just need to extract them from the resulting array
(?s)(?<=^Begin InputTables(?:(?!Begin OutputColumns).)*)Name ="([^"]*)"

Open in new window

The (?s) at the start indicates singleline mode (it can be activated that way).
0
Terry WoodsIT GuruCommented:
The (?:(?!Begin OutputColumns).)* part of the pattern says don't go past "Begin OutputColumns" trying to find a match.
0
aanuncioAuthor Commented:
TerryAtOpus: eventually I'll need to match anything between double quotes that are in turn between "Begin InputTables" and "Begin OutputColumns", but for now I want to search for the tables by their exact names.
0
Terry WoodsIT GuruCommented:
Then this should do the trick:
(?ms)(?<=^Begin InputTables(?:(?!Begin OutputColumns).)*)Name ="AGCOUNTY"

Open in new window

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
aanuncioAuthor Commented:
Should, but doesn't. It only finds the first match. On subsequent iterations, it misses "ELIGIBILITY" and "X".

Here's the code:

                Dim options As RegexOptions = RegexOptions.IgnoreCase Or RegexOptions.Multiline
                Dim pattern As String = "(?ms)(?<=^Begin InputTables(?:(?!Begin OutputColumns).)*)Name =""" & findText & """"
                Dim m As Match = Regex.Match(inputLines, pattern, options)

Open in new window

I can make it match the first, second or third lines between "Begin InputTables" and "Begin OutputColumns", but I can't make it find all of them using a single pattern. That wouldn't be a problem if I had a finite number of lines, but I don't.
0
aanuncioAuthor Commented:
By the way, what's the "(?ms)"?
0
aanuncioAuthor Commented:
TerryAtOpus: I got it. You were right. I am unworthy.
0
aanuncioAuthor Commented:
How do people get so smart?
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
.NET Programming

From novice to tech pro — start learning today.