Vim tip 27: regexp anchors
By default, regexp matches anywhere in the text. You can use line and word anchors to specify additional restrictions regarding the position of matches. These restrictions are made possible by assigning special meaning to certain characters (metacharacters) and escape sequences.
^restricts the match to the start-of-line^ThismatchesThis is a samplebut notDo This
$restricts the match to the end-of-line)$matchesapple (5)but notdef greeting():
^$match empty line\<patternrestricts the match to the start of a word- word characters include alphabets, digits and underscore
\<hismatcheshisorto-hisorhistorybut notthisor_hist
pattern\>restricts the match to the end of a wordhis\>matcheshisorto-hisorthisbut nothistoryor_hist
\<pattern\>restricts the match between start of a word and end of a word\<his\>matcheshisorto-hisbut notthisorhistoryor_hist
End-of-line can be
\r (carriage return), \n (newline) or \r\n depending on your system and fileformat setting.
See :h pattern-atoms for more details.
Video demo:
See also my Vim Reference Guide and curated list of resources for Vim.