【问题标题】:Is there a way to get the variables that were used in a RegEx.Replace to use in .NET?有没有办法让 RegEx.Replace 中使用的变量在 .NET 中使用?
【发布时间】:2009-07-23 17:54:48
【问题描述】:

例如,我有一个使用 \G 选项搜索的模式,因此它会记住上次搜索。我希望能够在 .NET c# 中重用这些(即:将匹配项保存到集合中)

例如:

string pattern = @"\G<test:Some\s.*";
string id = RegEx.Match(orig, pattern).Value;  
// The guy above has 3 matches and i want to save all three into a generic list

我希望这很清楚,如果没有,我可以详细说明。

谢谢 :-)

【问题讨论】:

    标签: .net regex


    【解决方案1】:

    您将需要使用 RegEx.Matches 函数并遍历集合。

    【讨论】:

    • 非常感谢,我正在尝试这个但没有运气 - 当我使用 RegEx.Match(orig, pattern) 时,它可以工作,如果我这样做:MatchCollection co = RegEx.Matches(orig, pattern );我得到 0 个结果。知道我在这里做错了什么吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-20
    • 2022-01-05
    • 2016-05-23
    • 1970-01-01
    相关资源
    最近更新 更多