gpt4 book ai didi

regex - Grep 正则表达式

转载 作者:IT王子 更新时间:2023-10-29 00:58:27 27 4
gpt4 key购买 nike

考虑这个文本文件:

TEST FILE : test                         #No match
#No match
Run grep "1133*" on this file #Match
#No match
This line contains the number 113. #Match
This line contains the number 13. #No match
This line contains the number 133. #No match
This line contains the number 1133. #Match
This line contains the number 113312. #Match
This line contains the number 1112. #No match
This line contains the number 113312312. #Match
This line contains no numbers at all. #No match

grep 命令如何计算 1133* 正则表达式?

echo "Consider this text file:

TEST FILE : test #No match
#No match
Run grep \"1133*\" on this file #Match
#No match
This line contains the number 113. #Match
This line contains the number 13. #No match
This line contains the number 133. #No match
This line contains the number 1133. #Match
This line contains the number 113312. #Match
This line contains the number 1112. #No match
This line contains the number 113312312. #Match
This line contains no numbers at all. #No match" | grep "1133*"

输出:

Run grep "1133*" on this file            #Match
This line contains the number 113. #Match
This line contains the number 1133. #Match
This line contains the number 113312. #Match
This line contains the number 113312312. #Match

为什么包含 113 的行是正数?

正则表达式 1133* 是否意味着除了找到包含单词 1133+anything else 的所有行?

这个例子是在 tldp regexp 上找到的文档页面。

最佳答案

您正在考虑一个 shell 通配符,其中 * 匹配任何内容。在 regular expressions , *quantifier这意味着它之前的任何内容的“零个或多个”,在本例中为 3

因此您的表达式表示 113 后跟零个或多个 3

关于regex - Grep 正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11953174/

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