Word Boundaries

A word boundary is a zero-width test between two characters. To pass the test, there must be a word character on one side, and a non-word character on the other side. It does not matter which side each character appears on, but there must be one of each.

Table 2 defines word characters. For the word boundary test only, which must always have two characters to consider, the beginning and end of the string are considered non-word characters.

To better understand the concept of a word boundary, consider the string:
HELLO WORLD!
Now, place an imaginary line between any two characters. These two characters, on either side of the line, are now the candidates for the test. In this example, the imaginary line is represented by a vertical bar between the letters W and O. Both characters are underlined for emphasis.
HELLO W|ORLD!

Because the characters W and O are both word characters, the imaginary line is not on a word boundary, and the test fails.

Now, place the imaginary line at the very beginning of the string:
|HELLO WORLD!

For this test, there is only one real character, H, so the beginning of the string counts as the second character. Since H is a word character, and the beginning of the string is considered a non-word character (for the word boundary test only), the imaginary line is on a word boundary, and the test passes.