I have a file "foo" with the following in it.:
mPosixHello
mPosixWorld
mPosix->ThisWontPrint()
mPosix.NorWillThis()
From the command line, I type:
egrep 'mPosix\B+' foo
As one would expect, it returns:
mPosixHello
mPosixWorld
Now, let's change the command to:
egrep -o 'mPosix\B+' foo
The output return is not what I would expect:
mPosix
mPosix
Why is this? I am expecting to see the same output as the first run. I thought -o prints out the actual substring that matched and not the entire line (in this case, they are the same thing aside from newline? Hmmm...)
Some useful info:
> egrep --version
egrep (GNU grep) 2.12
> uname -a
Linux TSU-Debian-Dev 3.2.0-4-amd64 #1 SMP Debian 3.2.63-2 x86_64 GNU/Linux
Any insight is appreciated. Thanks!
\B is not a character class. it is the word boundry anchor similar to $ (end of line) or ^ (start of line)
Anchors are a different breed. They do not match any character at all. Instead, they match a position before, after, or between characters. They can be used to "anchor" the regex match at a certain position.
TLDR;
anchors != character classes,
\b and \B basically ignore + and *
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다