The metacharacter \b is an anchor like the caret and the dollar sign. It matches at a position that is called a “word boundary”. This match is zero-length. There are three different positions that qualify as word boundaries: Before the first character in the string, if the first character is a word character.
A word boundary \b is a test, just like ^ and $ . When the regexp engine (program module that implements searching for regexps) comes across \b , it checks that the position in the string is a word boundary.
Introduction to the Python regex word boundaryBefore the first character in the string if the first character is a word character ( \w ). Between two characters in the string if the first character is a word character ( \w ) and the other is not ( \W – inverse character set of the word character \w ).
The regular expression \b[A]\w+ can be used to find all words in the text which start with A. The \b means to begin searching for matches at the beginning of words, the [A] means that these matches start with the letter A, and the \w+ means to match one or more word characters.
/the\>
See :help /ordinary-atom
I assume "regexp" means PCRE. It is worth noting that Vim's regex syntax differs from (and apparently predates) PCRE.
See also:
Use \<
and \>
for word start and word end, respectively.
E.g. In your specific case you would use:
/the\>/
If very magic
is turned on, then you shouldn't escape the >
character. See what's magic search.
SO in your case you'd do:
/\v<the>
it would search for only the word 'the'.
if you are trying to search a word at your cursor. you can just hit *, or # for backward search.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With