Link to home
Start Free TrialLog in
Avatar of Dario Somoza
Dario SomozaFlag for Uruguay

asked on

.NET RegEx to find all occurrences of substring matching specific pattern

I have two different strings, and need to identify the RegEx to use in order to find all occurrences matching a specific pattern.

Scenario #1:
Content of the input string:
Schema="[dbo]" Table="[TABLENAME]" Index="[INDEXNAME1]" IndexKind="NonClustered"/>
Schema="[dbo]" Table="[TABLENAME]" Index="[INDEXNAME3]" IndexKind="NonClustered"/>
Schema="[dbo]" Table="[TABLENAME]" Index="[INDEXNAME18]" IndexKind="NonClustered"/>
Schema="[dbo]" Table="[TABLENAME]" Index="[INDEXNAME22]" IndexKind="NonClustered"/>


Expected results (for instance in a MatchCollection): INDEXNAME1, INDEXNAME3, INDEXNAME18, INDEXNAME22

Scenario #2
Content of the input string:
WHERE ([FieldA] = 250 AND [FieldB] = 133 AND

Expected results: 250, 133

Could you please help on getting this RegEx?

Thanks
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

Avatar of Dario Somoza

ASKER

Shaun Vermaak, thanks for your reply:

Expression #1:
            Actually I referenced INDEXNAMEn, but that piece of content may vary, for instance:
            Schema="[dbo]" Table="[TABLENAME]" Index="[WHATEVER1]" IndexKind="NonClustered"/>
            Schema="[dbo]" Table="[TABLENAME]" Index="[SOMETHING3]" IndexKind="NonClustered"/>
            Schema="[dbo]" Table="[TABLENAME]" Index="[OTHER18]" IndexKind="NonClustered"/>
            Schema="[dbo]" Table="[TABLENAME]" Index="[ANOTHERONE22]" IndexKind="NonClustered"/>
           Expected result: WHATEVER1, SOMETHING3, OTHER18, ANOTHERONE22

Expression #2:
            Something might be wrong, since the provided expression returns a lot of matches (41)

            string pattern = @"\d*";
            string input = @"WHERE ([FieldA] = 250 AND [FieldB] = 133 AND";
            MessageBox.Show(Regex.Matches(input, pattern).Count.ToString()); //This shows 41 matches
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This worked! Thanks!