This question already has an answer here:
- Reference - What does this regex mean? 1 answer
debian@wifi:~$ echo "348dfgeccvdf" | grep -oP "\d+(?=\w{6,10})"
348
debian@wifi:~$ echo "348dfgeccvdf" | grep -oP "(?=\w{6,10})\d+"
348
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.
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.
Now here is another example:
echo "adabc adabb" |grep -oP "ad(?=abc)"
ad
echo "adabc adabb" |grep -oP "(?=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
?