#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    355
    Rep 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 01:33 PM.
    Gilgal's website:
    Wheel Of God
    Now easy to post scripture verses!
    Portfolio
  2. #2
  3. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    938
    Why sore them in an array? Why not do something like this:
    Code:
    var myNewString = myOldString.replace(/[:;,.?()]/g, "");
    ?

IMN logo majestic logo threadwatch logo seochat tools logo