如何在 grep -P 中转义 / 字符 '(?!.*//)word'转义评论



grep -P '(?!.*//)word'我学会了使用带有perl regex的grep -P排除grep中的模式。但我不知道如何排除//

我试过

  • /
  • /
  • \/

似乎什么都不起作用

使用

grep -P '^s*//.*(*SKIP)(*F)|word' file

查看正则表达式验证

解释

--------------------------------------------------------------------------------
^                        the beginning of the string
--------------------------------------------------------------------------------
s*                      whitespace (n, r, t, f, and " ") (0 or
more times (matching the most amount
possible))
--------------------------------------------------------------------------------
//                       '//'
--------------------------------------------------------------------------------
.*                       any character except n (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
(*SKIP)(*F)               skip and proceed searching for the next pattern
--------------------------------------------------------------------------------
|                        OR
--------------------------------------------------------------------------------
word                     'word'

最新更新