- 論壇徽章:
- 0
|
在研讀精華貼的過程中,發(fā)現(xiàn)如下內(nèi)容:
If the group doesn't participate in a match, i.e., it is part of an
alternative not taken or a repetition operator allows zero
repetitions of it, then the back reference makes the whole match
fail. For example, `(one()|two())-and-(three\2|four\3)' matches
`one-and-three' and `two-and-four', but not `one-and-four' or
`two-and-three'. For example, if the pattern matches `one-and-',
then its group 2 matches the empty string and its group 3 doesn't
participate in the match. So, if it then matches `four', then
when it tries to back reference group 3--which it will attempt to
do because `\3' follows the `four'--the match will fail because
group 3 didn't participate in the match.
百思不得其解 ,在Solaris bash環(huán)境中測試也未得結(jié)果,請大家?guī)兔忉屢幌,多謝多謝!
# cat tmp
one-and-three
two-and-four
one-and-four
two-and-three
# grep '\(one\(\)|two\(\)\)-and-\(three\2|four\3\)' tmp
# |
|