Java Reference
In-Depth Information
figureĀ 6-7
Here the Paul substring in JeanPaul will be changed to Ringo . You really only want to convert
the substring Paul where it is on its own, with a word boundary on either side. If you change your
regular expression code to:
var myRegExp = /\bPaul\b/gi;
you have your final answer and can be sure only Paul or paul will ever be matched.
grouping regular expressions
The final topic under regular expressions, before you look at examples using the match() ,
replace() , and search() methods, is how you can group expressions. In fact, it's quite easy. If you
want a number of expressions to be treated as a single group, you just enclose them in parentheses,
for example, /(\d\d)/ . Parentheses in regular expressions are special characters that group together
character patterns and are not themselves part of the characters to be matched.
Why would you want to do this? Well, by grouping characters into patterns, you can use the special
repetition characters to apply to the whole group of characters, rather than just one.
Let's take the following string defined in myString as an example:
var myString = "JavaScript, VBScript and PHP";
 
Search WWH ::




Custom Search