cygwin 中的正则表达式中的元字符不是大括号吗?

Aren't curly brackets the metacharacters in regular expressions in cygwin?

我想在 cygwin 中使用 grep 在文本文件中搜索 phone-number。 数字是0570-2770521,我用的是正则表达式 “[0-9]{4}-[0-9]{7}”,总命令为 grep "[0-9]{4}-[0-9]{7}" ./list.txt,但它不起作用。 然后我改成了grep "[0-9]\{4\}-[0-9]\{7\}" ./list.txt,成功了!

但是由于{}是元字符,如果将其转义,就只是字面字符,那么如何表示[0-9]的匹配次数呢?

是不是我理解错了? 希望有人能帮忙解释一下,先谢谢了!

此致!

man re_format:

Obsolete ("basic") regular expressions differ in several respects. [...] The delimiters for bounds are \{ and \}, with { and } by themselves ordinary characters.

使用 egrep(或等同于 grep -E)增强的正则表达式,您可能更熟悉。