To make it easier to find whole words, we can use the metacharacter
\b. It marks the beginning and the end of an alphanumeric sequence*. Also, since it only serves to mark this locations, it actually matches no character on its own.
*: It is common to call an alphanumeric sequence a word, since we can catch it's characters with a
\w (the word characters class). This can be misleading, though, since
\w also includes numbers and, in most flavors, the underscore.
|No, since there's no ocurrence of the whole word |
|Yes, since there's nothing before nor after |
|Yes: there's nothing before |
|Yes, since there's nothing before |
|Yes, since there's nothing after |
This is the opposite of
\b, matching against the location of every non-boundary character. Like
\b, since it matches locations, it matches no character on its own. It is useful for finding non whole words.
|Yes, since |
|Yes, it matches the second comma because |