Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一些符合格式的文本
text ( text + numbers | text + numbers | 2-4 digit number text)
我有兴趣从 C# 中的这个字符串中提取 2-4 位数字。我的正则表达式字符串是
.*?\|.*?\|([0-9][0-9][0-9]?[0-9]?)
这会正确返回字符串是否匹配,但我无法仅提取数字。
我试过调用 regex.match(input).Value,但它返回整个输入。
我一定遗漏了一些东西 - 任何帮助表示赞赏:)
您的正则表达式用您想要的值定义了一个Group- 内括号。仅使用ValueMatch 对象返回与正则表达式匹配的整个字符串。
Group
Value
使用 regex.Match(input).Groups[1].Value 提取数字。