
November 6th, 2008, 12:05 PM
|
|
Contributing User
|
|
Join Date: Aug 2004
Posts: 355
Time spent in forums: 1 Day 2 h 3 m 31 sec
Number of bans: 1
Reputation Power: 0
|
|
|
Javascript regex for eliminating punctuations array
I made an array of punctuation which I want to eliminate from the string:
Code:
/*to eliminate the punctuations*/
var punctuations = new Array();
punctuations[0] = ":";
punctuations[1] = ";";
punctuations[2] = ",";
punctuations[3] = ".";
punctuations[4] = "?";
punctuations[5] = "(";
punctuations[6] = ")";
var myOldString = searchChapWords[i].innerHTML;
for(punct=0; punct<punctuations.length; punct++){
var myNewString = myOldString.replace(/"punctuations[punct]"/g, punctuations);
}
document.write("Old string = " + myOldString);
document.write("<br />New string = " + myNewString);
/*end*/
What's the correct way of doing it?
Last edited by gilgalbiblewhee : November 6th, 2008 at 12:33 PM.
|