小编Sur*_*ter的帖子

GREP + REGEX 没有像我预期的那样工作

我试图从 ls /dev 获取输出以匹配以 1-4 之间的数字结尾的“tty”。

所以从:

tty5
tty4
tty2
tty6
tty1
Run Code Online (Sandbox Code Playgroud)

应该匹配:

tty4
tty2
tty1
Run Code Online (Sandbox Code Playgroud)

正则表达式

"\s([tty]+[0-4])\s"
Run Code Online (Sandbox Code Playgroud)

RegExr 中工作

我试过在 grep 中使用它:

ls /dev | grep -E \s([tty]+[0-4])\s

ls /dev | grep -E \s([tty]\+\[0-4])\s

ls /dev | grep -Ex \s([tty]+[0-4])\s

ls /dev | grep -P \s([tty]+[0-4])\s
Run Code Online (Sandbox Code Playgroud)

正如我在其他帖子中读到的那样,我仍然无法使其工作。

grep arch-linux regular-expression

8
推荐指数
2
解决办法
1575
查看次数

标签 统计

arch-linux ×1

grep ×1

regular-expression ×1