Java Reference
In-Depth Information
between two words. The following table lists some of the most common position characters and
what they do:
position CharaCter
desCription
The pattern must be at the start of the string, or if it's a multi‐line string,
then at the beginning of a line. For multi‐line text (a string that contains
carriage returns), you need to set the multi‐line flag when defining the
regular expression using /myreg ex/m . Note that this is only applicable
to IE 5.5 and later and NN 6 and later.
^
The pattern must be at the end of the string, or if it's a multi‐line string,
then at the end of a line. For multi‐line text (a string that contains carriage
returns), you need to set the multi‐line flag when defining the regular
expression using /myreg ex/m . Note that this is only applicable to IE 5.5
and later and NN 6 and later.
$
This matches a word boundary, which is essentially the point between a
word character and a non‐word character.
\b
This matches a position that's not a word boundary.
\B
For example, if you wanted to make sure your pattern was at the start of a line, you would type the
following:
^myPattern
This would match an occurrence of myPattern if it was at the beginning of a line.
To match the same pattern, but at the end of a line, you would type the following:
myPattern$
The word‐boundary special characters \b and \B can cause confusion, because they do not match
characters but the positions between characters.
Imagine you had the string "Hello world!, let's look at boundaries said 007." defined in the
code as follows:
var myString = "Hello world!, let's look at boundaries said 007.";
To make the word boundaries (that is, the boundaries between the words) of this string stand out,
let's convert them to the | character:
var myRegExp = /\b/g;
myString = myString.replace(myRegExp, "|");
alert(myString);
You've replaced all the word boundaries, \b , with a | , and your message box looks like the one in
Figure 6-4.
Search WWH ::




Custom Search