Regex Question

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I am new to C#. I have the following test code and it does not work as expected on the regex. The regex works in ruby and Regex Coach so I know it is good. It returns 5 values. In c# it returns 1 match which is the original
string. What is my mistake?
string[] rxVals = new string[10];

string regex = @"(w+),s+(w+)s+(d+),s+(d+),s+(d+)";<br/>
string text = "Wednesday, February 15, 2012, 11:00 AM CST";<br/>
Regex rx = new Regex(regex, RegexOptions.IgnoreCase);<br/>
MatchCollection matches = rx.Matches(text);<br/>
int vCnt = 1;<br/>
foreach (Match match in matches)<br/>
{<br/>
GroupCollection groups = match.Groups;<br/>
rxVals[vCnt] = groups[0].Value;<br/>
vCnt++;<br/>
}

View the full article
 

Similar threads

R
Replies
0
Views
124
Richard.Haggard
R
E
Replies
0
Views
90
etl2016
E
A
Replies
0
Views
120
ACalafiore
A
W
Replies
0
Views
89
William A Wang
W
I
Replies
0
Views
153
Innovators World Wide
I
Back
Top