468,170 Members | 1,982 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,170 developers. It's quick & easy.

quick question on RegEx

while writing a RegEx, you implicily name your Groups:

\b(?<month>\d{1,2})/(?<day>\d{1,2})/(?<year>\d{2,4})\b

so, why isn't .Name a property of a
System.Text.RegularExpressions.RegEx.Group?

more importantly, how can you refer to a Group by name in code?
Nov 19 '05 #1
1 1350

You can access the names of groups in a Regex through the GetGroupNames
function of the Regex object:

Dim r as New Regex("\b(?<month>\d{1,2})/(?<day>\d{1,2})/(?<year>\d{2,4})\b")
Dim GroupNames as String() = r.GetGroupNames
Accessing groups by name is accomplished like this:

Dim r as New Regex("\b(?<month>\d{1,2})/(?<day>\d{1,2})/(?<year>\d{2,4})\b")
Dim m as Match = r.Match("Today is 08/26/2003.")
Dim y as String = m.Groups("year").Value
Brian Davis
www.knowdotnet.com
"K. Shier" <ks*****@spamAtYourOwnRisk.yahoo.com> wrote in message
news:uN**************@tk2msftngp13.phx.gbl...
while writing a RegEx, you implicily name your Groups:

\b(?<month>\d{1,2})/(?<day>\d{1,2})/(?<year>\d{2,4})\b

so, why isn't .Name a property of a
System.Text.RegularExpressions.RegEx.Group?

more importantly, how can you refer to a Group by name in code?

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Tim Conner | last post: by
5 posts views Thread by Troy | last post: by
6 posts views Thread by Extremest | last post: by
7 posts views Thread by Extremest | last post: by
10 posts views Thread by yoni | last post: by
3 posts views Thread by aspineux | last post: by
15 posts views Thread by morleyc | last post: by
Xx r3negade
2 posts views Thread by Xx r3negade | last post: by
1 post views Thread by gcdp | last post: by
reply views Thread by kamranasdasdas | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.