grep command with a lookahead pattern does not select anything

后端 未结 1 610
灰色年华
灰色年华 2021-01-22 05:41

I was trying to use the following grep command:

grep \'(.*)(?=(png|html|jpg|js|css)(?:\\s*))(png|html|jpg|js|css.*\\s)\' file

File contains the

相关标签:
1条回答
  • 2021-01-22 06:28

    You are using a PCRE regex with the POSIX BRE engine that is default grep engine.

    To make those patterns work, you should use -P option (available in GNU grep):

    grep -P 'YOUR_PCRE_PATTERN'
         ^^
    

    To develop and test PCRE patterns, a well-known regex101.com is usually recommended.

    Note that on Mac OS, you may install GNU grep via brew.

    0 讨论(0)
提交回复
热议问题