RegEx

  • Thread starter Thread starter elziko
  • Start date Start date
E

elziko

I have created a Regular Expression to get the text between two strings for
example, starting in AB and ending in CD:

Dim reCategory As New Regex("AB((.|\n)*?)CD", RegexOptions.IgnoreCase)

This works but also returns the original AB and CD text in the matches. Is
there an easy way of making sure each match discards the AB and CD text?
 
elziko,
Look at the Match.Groups property & Regular Expression Grouping Constructs.

If I want the middle stuff specifically I normally make it a named group.

Something like:
Dim reCategory As New Regex("AB(?'mystuff'(.|\n)*?)CD",
RegexOptions.IgnoreCase)
Dim match As Match = reCategory.Match("ABxyzCD")
Debug.WriteLine(match.Groups("mystuff"), "mystuff")

Hope this helps
Jay
 
Back
Top