【发布时间】:2021-04-16 06:08:44
【问题描述】:
grep -P '(?!.*//)word' 我学会了在 grep 中使用 grep -P 和 perl 正则表达式来排除模式。但我不知道如何排除//
我试过了
/\/\\/
似乎没有任何效果
【问题讨论】:
-
/并不特别......你能展示一些示例输入行和这些行所需的确切输出吗?如果你使用grep -P '^(?!.*//).*word',它可以工作吗?
grep -P '(?!.*//)word' 我学会了在 grep 中使用 grep -P 和 perl 正则表达式来排除模式。但我不知道如何排除//
我试过了
/\/\\/似乎没有任何效果
【问题讨论】:
/ 并不特别......你能展示一些示例输入行和这些行所需的确切输出吗?如果你使用grep -P '^(?!.*//).*word',它可以工作吗?
使用
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'
【讨论】: