如何解释相同结构的表达式`(?= \ w {6,10})\ d +和(?= abc)ad? [英] How to explain the same structure expression `(?=\w{6,10})\d+ and (?=abc)ad`?

查看:167
本文介绍了如何解释相同结构的表达式`(?= \ w {6,10})\ d +和(?= abc)ad?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

debian@wifi:~$ echo "348dfgeccvdf" | grep -oP "\d+(?=\w{6,10})"
348
debian@wifi:~$ echo "348dfgeccvdf" | grep -oP "(?=\w{6,10})\d+"
348

对于\d+(?=\w{6,10}),这是标准的正向向前表达.
正如WiktorStribiżew在帖子中所说的那样
位置和否定后视
负向后搜索语法以(?<! and ends with the unescaped )开头.不管它出现在图案的开始,中间还是结尾,它都不会成为负面的向后看.
位置和整个前瞻(后向)表达之间可能没有关系.

For \d+(?=\w{6,10}) ,it is the standard positive look ahead expression.
As Wiktor Stribiżew say in the post
position and negative lookbehind
The negative lookbehind syntax starts with (?<! and ends with the unescaped ). Whether it appears at the start, middle or end of the pattern, it does not stop from being a negative lookbehind.
Maybe it's no realtionship between position and whole lookahead(lookbehind) expression.

根据相同的逻辑推论正面的展望,例如Wiktor Stribiewew对背后的负面展望说:

To infer for positive look ahead according to the same logic ,such as Wiktor Stribiżew say for negative lookbehind:

"\d+(?=\w{6,10})" == "(?=\w{6,10})\d+"

他们俩都对未来充满信心.

Both of them are positive look ahead.

现在这是另一个示例:

echo  "adabc  adabb" |grep -oP  "ad(?=abc)"
ad
echo  "adabc  adabb" |grep -oP  "(?=abc)ad"

为什么"ad(?=abc)"不等于"(?=abc)ad"?
如何解释相同结构的表达式(?=\w{6,10})\d+ and (?=abc)ad?

Why "ad(?=abc)" is not equal to "(?=abc)ad" ?
How to explain the same structure expression (?=\w{6,10})\d+ and (?=abc)ad ?

推荐答案

为什么"ad(?= abc)ad不等于(?= abc)ad"?

Why "ad(?=abc)" is not equal to "(?=abc)ad" ?

ad(?=abc)解释ad后跟abc,而(?=abc)ad与任何输入字符串都不匹配.导致期望'跟随abc'(?=abc),但在正向超前后定义ad! .模式应类似于此(?=abc)\w+,以与此输入字符串abcad

ad(?=abc) explains ad followed by abc whereas (?=abc)ad will not match with any input string. Cause expecting 'followed by abc' (?=abc) but defining ad after positive lookahead ! . Pattern should be like this (?=abc)\w+ to match with this input string abcad

如何解释相同的结构表达式(?= \ w {6,10})\ d +和(?= abc)ad?

How to explain the same structure expression (?=\w{6,10})\d+ and (?=abc)ad ?

(?=\w{6,10})\d+对于任何输入字符串,此模式也将与此(?=abc)ad不匹配.模式应该是这样的:

(?=\w{6,10})\d+ this pattern also will not match as this (?=abc)ad for any input string. Pattern supposed to be like this :

(?=\w{6,10})\w+(?=abc)\w+.

这篇关于如何解释相同结构的表达式`(?= \ w {6,10})\ d +和(?= abc)ad?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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