C#正则表达式组名称 [英] C# regular expression group names
问题描述
这是我的正则表达式之一:
This is one of my regular expressions:
(?<RollP>[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?),(?<RollI>[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)
输入将是2个以逗号分隔的浮点数
The input would be 2 floats separated by a comma
2.34,-23
它创建了两个主要的组"RollP"和"RollI",我希望能够采用GroupCollection值并将其放入像这样的字典中
It creates 2 main groups "RollP" and "RollI" and i want to be able to take the GroupCollection values and put it into a dictionary like so
"RollP":"2.34"
"RollI":"-23"
但是使用reg.GroupNameFromNumber
让我感到困惑.整个组表达式中有未命名的组,以检查浮点数.
But using reg.GroupNameFromNumber
has me stumped. There are unnamed groups within the overall group expressions to check the floats.
How could i recurse the list or change the expression to get me to the top name which would be either RollP or RollI and still give me the associated string value?
推荐答案
尝试通过Name
为Groups
编制索引:
Try indexing theGroups
byName
:
myMatch.Groups["RollP"]
等等.
这篇关于C#正则表达式组名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!