8.3 正后顾

正后顾会查看左边的内容,这与正前瞻方向相反。其语法是:

  1. (?i)(?<=ancyent) marinere

正后顾使用小于号(<),提醒你后顾是哪个方向。请在RegExr中试一下,看看有什么不同。被标亮的是marinere而不是ancyent。为什么?因为正后顾的模式是匹配的条件,不会包含在匹配结果中。

在Perl语言中这样做:

  1. perl -ne 'print if /(?i)(?<=ancyent) marinere/' rime.txt

在ack中这样做:

  1. ack -i '(?<=ancyent) marinere' rime.txt