Java Reference
In-Depth Information
figure 6-4
You can see that the position between any word character (letters, numbers, or the underscore
character) and any non‐word character is a word boundary. You'll also notice that the boundary
between the start or end of the string and a word character is considered to be a word boundary.
The end of this string is a full stop. So the boundary between the full stop and the end of the string
is a non-word boundary, and therefore no | has been inserted.
If you change the regular expression in the example, so that it replaces non-word boundaries as
follows:
var myRegExp = /\B/g;
you get the result shown in Figure 6-5.
Now the position between a letter, number, or underscore and another letter, number, or underscore
is considered a non-word boundary and is replaced by an | in the example. However, what is
slightly confusing is that the boundary between two non‐word characters, such as an exclamation
mark and a comma, is also considered a non-word boundary. If you think about it, it actually does
make sense, but it's easy to forget when creating regular expressions.
You'll remember this example from when you started looking at regular expressions:
<!DOCTYPE html>
 
<html lang="en">
<head>
Search WWH ::




Custom Search