regex =>在两个匹配项之间提前查找c# [英] regex=>lookahead between two matches c#

查看:91
本文介绍了regex =>在两个匹配项之间提前查找c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

const string numericReg = "\\d+"; // Matches a digit character. Equivalent to [0-9].
const string realNumsReg = numericReg + b + "(\\." + b + numericReg + ")?";
        const string b = "\\s*";




这个说法是正确的:




This statement is true :

private const string rte = "(?<rate>" + realNumsReg + ")" +
                          "(?=(?<rte1>" + b + "qs " + "))";





这个说法是正确的:



and

This statement is true :

private const string barl = "(?<barl>" + numericReg + ")" +
                                   "(?=((?<q>" + b + "point to print )))";




这对于rte是正确的:




this is true for rte :

MatchCollection s = Regex.Matches
                ("3000 qs / min", rte , RegexOptions.IgnoreCase);



这对于barl是正确的:



this is true for barl:

MatchCollection s = Regex.Matches
                ("6 point to print  ", barl , RegexOptions.IgnoreCase);



为什么错了?



Why is this wrong?

MatchCollection s = Regex.Matches
               ("6 point to print  3000 qs/ min", barl+b+rte  , RegexOptions.IgnoreCase);

推荐答案

将此模式与ExplicitCapture作为选项一起使用:
\b*(?<points>\d{1}) point to print (?<qs>\d{1,4})\b</qs></points>

结果-> 2个匹配项:63000

是您要找的吗?
Use this pattern with ExplicitCapture as an option:
\b*(?<points>\d{1}) point to print (?<qs>\d{1,4})\b</qs></points>

Result -> 2 matches: 6 and 3000

Is that you''re looking for?


这篇关于regex =&gt;在两个匹配项之间提前查找c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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