正则表达式 – 行结束char($)在方括号内不起作用
发布时间:2020-12-14 06:02:18 所属栏目:百科 来源:网络整理
导读:将$放在方括号内对grep不起作用. ~ $echo -e "hellonthere" example.txt~ $grep "hello$" example.txt hello~ $grep "hello[$]" example.txt ~ $ 这是grep中的错误还是我做错了什么? 解决方法 这就是应该做的. [$] …定义匹配一个字符$的字符类. 因此,这将
将$放在方括号内对grep不起作用.
~ $echo -e "hellonthere" > example.txt ~ $grep "hello$" example.txt hello ~ $grep "hello[$]" example.txt ~ $ 这是grep中的错误还是我做错了什么? 解决方法
这就是应该做的.
[$] …定义匹配一个字符$的字符类. 因此,这将匹配包含hello $的行. 有关正式规范,请参见the POSIX RE Bracket Expression definition.引用完整定义:
因此,任何括号表达式都匹配单个元素. 而且,在the BRE Anchoring Expression definition:年
因此 – 从BRE开始,grep默认识别的regexp格式没有参数 – 如果$不在表达式的末尾,则不需要将其识别为锚. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |