I am learning bash and I have come across regular expressions. 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
. I actually tried it out of desperation when I couldn't understand why \\b
wasn't working.
You are proabably using grep \\bword\\b
which is really grep bwordb
after bash parses the backslashes.
Use grep '\\bword\\b'
(note the single-quotes).
您也可以使用grep -w word
仅匹配整个单词。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.