[英]using \b with grep pattern
I am learning bash and I have come across regular expressions. 我正在学习bash,并且遇到了正则表达式。 There is an exercise where I have to match a word and I tried to use \\b<word>\\b
but for some reason it was not matched until I used \\\\b<word>\\\\b
. 在一个练习中,我必须匹配一个单词,但是我尝试使用\\b<word>\\b
但是由于某种原因,直到我使用\\\\b<word>\\\\b
才使它不匹配。 I actually tried it out of desperation when I couldn't understand why \\b
wasn't working. 当我不明白\\b
为什么不起作用时,我实际上是出于绝望而尝试了。
You are proabably using grep \\bword\\b
which is really grep bwordb
after bash parses the backslashes. 您可能正在使用grep \\bword\\b
,在bash解析反斜杠后,它实际上是grep bwordb
。
Use grep '\\bword\\b'
(note the single-quotes). 使用grep '\\bword\\b'
(注意单引号)。
您也可以使用grep -w word
仅匹配整个单词。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.