By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,733 Members | 1,171 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,733 IT Pros & Developers. It's quick & easy.

How do I get the pattern text of a regular expression group

P: n/a
Assuming the following code:
Dim strPattern As String = "(\d{3})(-)(\d{4})"
Dim strMatch As String = "555-1234"
Dim regExp As New RegEx(strPattern)
Dim matches As MatchCollection = regExp.Matches(strMatch)
Dim match As Match = matches(0)
Dim groups As GroupCollection = match.Groups
Dim group As Group = groups(1)

Debug.WriteLine(group.Success, "group.Success") 'True
Debug.WriteLine(group.Index, "group.Index") '0
Debug.WriteLine(group.Length, "group.Length") '3
Debug.WriteLine(group.Value, "group.Value") '555

How do I get the actual text of the PATTERN representing the matched
group? I want the segment of the pattern, not the matched value so I
would like to see "(\d{3})".

Do I need to create a regular expression to parse my regular expression?
Ooh, that sounds ominous.

Sometimes the greatest solutions come from the simplest logic.
Being told "No" is merely the incentive to do it anyway.

*** Sent via Developersdex ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.