111,096
社区成员




Regex testXpress = new Regex(
@"^\s*(?:" +
@"(?:" +
@"(?:(?<low_bound>\d+(?:\.\d+)?))" +
@"\s*(?:-|~)\s*" +
@"(?:(?<high_bound>\d+(?:\.\d+)?))" +
")" +//0.78 - 1.23; 1-2.24; 4.3 -6; 5-9
@"|(?:(?:≤|(?:<=))\s*(?<high_bound>\d+(?:\.\d+)?))" + //<= 1.23; ≤1.12; <=1; ≤ 2
@"|(?:(?:≥|(?:>=))\s*(?<low_bound>\d+(?:\.\d+)?))" + //>= 1.23; ≥1.12; >=1; ≥ 2
@"|(?:(?:<|<)\s*(?<high_bound>\d+(?:\.\d+)?))" + //< 1.23; <1.12; <1; < 2
@"|(?:(?:>|>)\s*(?<low_bound>\d+(?:\.\d+)?))" + //> 1.23; >1.12; >1; > 2
@"|(?<accurate>\d+(?:\.\d+)?)" + // 12.45; 36
@")\s*$"
);
Match mc = testXpress.Match(textBox1.Text);
if (mc.Success)
{
foreach (Group gp in mc.Groups)
{
//string name = ?这里怎么获得捕获组的名字》?
foreach (Capture cp in gp.Captures)
{
//do something with name and cp.value
}
}
}
GroupCollection groups = regex.Match(line).Groups;
foreach (string groupName in regex.GetGroupNames())
{
Console.WriteLine(
"Group: {0}, Value: {1}",
groupName,
groups[groupName].Value);
}
[/quote]
严重同意GroupCollection groups = regex.Match(line).Groups;
foreach (string groupName in regex.GetGroupNames())
{
Console.WriteLine(
"Group: {0}, Value: {1}",
groupName,
groups[groupName].Value);
}
if (mc.Success)
{
foreach (Capture cp in mc.Groups["low_bound"].Captures)
{
//do something with name and cp.value
}
}