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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top