我有一些数据,我喜欢从右到左提取数据。样本数据
1,4,34
5,15
22
预期输出:
One=34 Two=4 Three=1
One=15 Two=5
One=22
这是我所拥有的正则表达式经验。
(?:(?<three>\d+),)?(?:(?<two>\d+),)?(?<one>\d+)$
但这给出了:
One=34 Two=4 Three=1
One=15 Three=5
One=22
所以当只有两次提取时就会失败。有什么好主意吗? PS我没有任何反转工具
^((?:(?<three>\d+),)(?:(?<two>\d+),)|(?:(?<two2>\d+),)?)(?<one>\d+)$
是我能想到的唯一可能的解决方案,但由于捕获组必须都有不同的名称,因此最终会得到 2 个具有不同名称的“两个”。