Dario Somoza
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
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
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.Matc hes(input, pattern).Count.ToString()) ; //This shows 41 matches
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.Matc
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This worked! Thanks!
https://www.regex101.com/r
and
\d*
https://www.regex101.com/r