Java Reference
In-Depth Information
Save the page as ch9_examp5.htm. Load the page into your browser and you should see what is shown
in Figure 9-13.
Figure 9-13
Click the Replace Single Quotes button to see the single quotes in the text area replaced as in
Figure 9-14.
Figure 9-14
Try entering your own text with single quotes into the text area and check the results.
You can see that by using regular expressions, you have completed a task in a couple of lines of simple
code. Without regular expressions, it would probably take four or fi ve times that amount.
Let's look fi rst at the replaceQuote() function in the head of the page where all the action is.
function replaceQuote(textAreaControl)
{
var myText = textAreaControl.value;
var myRegExp = /\B'|'\B/g;
Search WWH ::




Custom Search