Regex 正则表达式-Linux
我们可以搜索像“\w\w\w\d”这样的模式吗?它在grep中表示三个字母后跟一个数字?它不起作用。在linux终端上有没有同样的方法 例如,我想匹配'ABC9'或'NMJ6'等grep-p“\w\w\d” 添加颜色,使其真正脱颖而出。 例如:Regex 正则表达式-Linux,regex,linux,grep,Regex,Linux,Grep,我们可以搜索像“\w\w\w\d”这样的模式吗?它在grep中表示三个字母后跟一个数字?它不起作用。在linux终端上有没有同样的方法 例如,我想匹配'ABC9'或'NMJ6'等grep-p“\w\w\d” 添加颜色,使其真正脱颖而出。 例如: echo 'blahblahABC9blahblah' | grep --color -P '\w\w\w\d' echo ABC9 | grep -E '[[:alpha:]]{3}[[:digit:]]' - 例如: echo 'blahblahA
echo 'blahblahABC9blahblah' | grep --color -P '\w\w\w\d'
echo ABC9 | grep -E '[[:alpha:]]{3}[[:digit:]]' -
例如:
echo 'blahblahABC9blahblah' | grep --color -P '\w\w\w\d'
echo ABC9 | grep -E '[[:alpha:]]{3}[[:digit:]]' -
给我们一个你想要匹配的字符串的例子。
Finally, certain named classes of characters are predefined
within bracket expressions, as follows. Their names are self
explanatory, and they are [:alnum:], [:alpha:], [:cntrl:],
[:digit:], [:graph:], [:lower:], [:print:], [:punct:], [:space:],
[:upper:], and [:xdigit:]. For example, [[:alnum:]] means
[0-9A-Za-z], except the latter form depends upon the C locale and
the ASCII character encoding, whereas the former is independent
of locale and character set. (Note that the brackets in these
class names are part of the symbolic names, and must be included
in addition to the brackets delimiting the bracket expression.)
Most meta-characters lose their special meaning inside bracket
expressions. To include a literal ] place it first in the list.
Similarly, to include a literal ^ place it anywhere but first.
Finally, to include a literal - place it last.