Grep中“词"的含义 [英] The meaning of 'word' in Grep
问题描述
在 grep 的手册页中,它说:
In the man page for grep it says that:
> The symbols < and > respectively match the empty string at the
> beginning and end of a word.
这里的词是什么意思?
我知道这个词是在 -w 中定义的,但这里有证据表明它在这种情况下具有不同的含义:
I know that word is defined in -w, but here is the proof that it has a different meaning in this context:
如果文件 'test' 包含 hi/
,并且我 grep -w 'hi/' test
,我得到一个匹配,但是如果我 grep 'hi/>'测试
,我没有.
If file 'test' contains hi/
, and I grep -w 'hi/' test
, I get a match,
but if I grep 'hi/>' test
, I don't.
推荐答案
单词的开头是单词字符(字母、数字或下划线),前面没有另一个单词字符,单词的结尾是一个单词字符,后面没有另一个单词字符.那么单词"就是一系列单词字符.
The beginning of a word is a word character (a letter, number, or underscore) that is not preceded by another word character, and the end of a word is a word character that is not followed by another word character. A "word" is then just a series of word characters.
hi/>
不匹配 hi/
的原因是因为 >
前面是一个非单词字符 (/
),所以它不能是词尾的位置.
The reason hi/>
doesn't match hi/
is because the >
is preceded by a non-word character (/
), and so that can't be the location of an end-of-word.
这篇关于Grep中“词"的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!