【问题标题】:regex: matching same expression unknown number of times正则表达式:匹配相同的表达式未知次数
【发布时间】:2009-04-27 23:12:15
【问题描述】:

在这里的一些人的帮助下,我有一些正则表达式来匹配不在括号中的引号中的字符串:

"one" - matches
("two") - doesn't match

是否可以重复匹配所以输入:

"one" ("two") "three"

会返回一和三吗?我唯一能想到的就是捕获剩余的内容并使用相同的正则表达式重新处理,即:

process > "one" ("two") "three" - returns one and "("two") "three""
process > ("two") "three"       - returns failed and "three", not sure how but hey
process > "three"

我现在正在学习正则表达式,所以想知道这个功能是否内置?

注意:这可能是 refering to already existing group in regex, c# 的重复,但不够清楚,我无法理解:(。

【问题讨论】:

    标签: .net regex


    【解决方案1】:

    您需要Regex.Matches() 函数,该函数返回与正则表达式匹配的所有子字符串。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多