gpt4 book ai didi

regex - grep环顾四周比赛不工作

转载 作者:行者123 更新时间:2023-12-05 08:58:23 25 4
gpt4 key购买 nike

我听说 grep 具有环视支持。我试图在答案中排除带有 grep 的行,因为显然它通常会在那里。我只是想检查我的 mysqld 服务器是否基本正常运行。

我正在尝试的正则表达式:

^(?!.*grep)(?=.*mysql).*

命令行。我试图匹配的顶线,我试图排除的底线。

root:~# ps aux | grep mysqld_safe
root 28012 0.0 0.1 4408 712 pts/0 S 18:00 0:00 /bin/sh /usr/bin/mysqld_safe
root 29167 0.0 0.1 9392 900 pts/1 S+ 20:51 0:00 grep --color=auto mysqld_safe

这是我的查询:

http://regex101.com/r/qK3cI5

# ps aux | grep '^(?!.*grep)(?=.*mysql).*'
(nothing)

最佳答案

  • 要使用前瞻/后视,您需要将 -P 选项添加到您的 grep(如果您的 grep 支持它)。因为 PCRE 支持它们。

  • 当你 grep ps 输出时有一个常见的技巧,但想排除 grep 进程本身,你可以例如:

    ps -ef|grep [m]ysql

ps aux|grep [m]ysql

关于regex - grep环顾四周比赛不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23555156/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com