regex - "*"在 grep 的正则表达式中的含义

标签 regex linux grep

我无法找到 * 在 grep 命令中的作用。我正在关注这个例子:

ian@attic4:~/lpi103-7$ grep "p*" text1
1 apple
2 pear
3 banana

如果有p*为什么会出现banana

最佳答案

* 符号表示“0 次或更多次”,因此 p 字符不需要出现在匹配的行中。如果您希望 p 字符至少出现一次,请改用 +

关于regex - "*"在 grep 的正则表达式中的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42029887/

相关文章:

regex - Jmeter中的正则表达式提取器

regex - 需要 SED 或 AWK 脚本来做 strlen 优化

php - <?PHP、REGEX 和我。三幕悲剧

linux - CENTOS 7 上出现错误 : This site can’t be reached while installing laravel 5. 7

python - 构建 Cython 扩展时出现错误 : ‘PyThreadState’ {aka ‘struct _ts’ } has no member named ‘exc_type’ ; did you mean ‘curexc_type’ ?

RegEx 用于选择路径的第一个元素

linux - python subprocess.readline() 在调用另一个 python 脚本时阻塞

linux - Grep,查找具有确切数量的匹配模式的行

linux - 优化 grep、awk 和 sed shell 内容

linux - 以下 "top"命令: top -p `pgrep process-name | tr "\\n" "," | sed 's/,$//' `的语法简单解释是什么