如何使用grep搜索包含数字的行?
记得“\d”可以表示任意数字,遂写成grep "\d" test.txt
没有返回任何数据, 难道不支持“\d”
你在命令行下执行man grep查看帮助,可以看到grep是支持多种正则表达式的,需要用参数去切换。
Matcher Selection -E,--extended-regexp Interpret PATTERN as an extended regular expression (ERE,see below). (-E is specified by POSIX.) -F,--fixed-strings Interpret PATTERN as a list of fixed strings,separated by newlines,any of which is to be matched. (-F is specified by POSIX.) -G,--basic-regexp Interpret PATTERN as a basic regular expression (BRE,see below). This is the default. -P,--perl-regexp Interpret PATTERN as a Perl regular expression (PCRE,see below). This is highly experimental and grep -P may warn of unimplemented features.
而默认情况下,grep只支持basic regex
“\d” 不被支持是因为它不属于basic regex。
那么basic regex有哪些?“\d” 又属于哪类正则表达式呢?
原文链接:https://www.f2er.com/regex/362557.html