C#正则表达式组名称 [英] C# regular expression group names

查看:178
本文介绍了C#正则表达式组名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的正则表达式之一:

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?

推荐答案

尝试通过NameGroups编制索引:
Try indexing the Groups by Name:
myMatch.Groups["RollP"]


等等.


这篇关于C#正则表达式组名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆