I have the following code:
string pattern =
@"(\{)|(})|(\() |(\))|(\[)|(])|(\^)|(\*)|(/)|(-)|(\+)|(%)";
Regex regex = new Regex(pattern);
string input = "QTY * ESTIMATED COST + 2";
string[] tokens = regex.Split(inp ut);
for (int i = 0; i != tokens.Length; i++)
{
Console.WriteLi ne("Token {0} = {1}", i, tokens[i].Trim());
}
Console.ReadLin e();
According to the documentation on the Split function, the returned
string array will include the captures if I use capturing groups. IOW, I
should get an array containing 5 elements. Instead I'm only getting
three (QTY, ESTIMATED COST and 2). What am I doing wrong?
--
There are 10 kinds of people. Those who understand binary and those who
don't.
(Pull the pin to reply)
string pattern =
@"(\{)|(})|(\() |(\))|(\[)|(])|(\^)|(\*)|(/)|(-)|(\+)|(%)";
Regex regex = new Regex(pattern);
string input = "QTY * ESTIMATED COST + 2";
string[] tokens = regex.Split(inp ut);
for (int i = 0; i != tokens.Length; i++)
{
Console.WriteLi ne("Token {0} = {1}", i, tokens[i].Trim());
}
Console.ReadLin e();
According to the documentation on the Split function, the returned
string array will include the captures if I use capturing groups. IOW, I
should get an array containing 5 elements. Instead I'm only getting
three (QTY, ESTIMATED COST and 2). What am I doing wrong?
--
There are 10 kinds of people. Those who understand binary and those who
don't.
(Pull the pin to reply)
Comment