MSDN > Home page del forum > Regular Expressions > Replace all unwanted characters with a regular expression - how?
Formula una domandaFormula una domanda
 

Con rispostaReplace all unwanted characters with a regular expression - how?

  • mercoledì 9 luglio 2008 21.10BlackCatBone Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    Greetings,

    I need to replace all characters in a string that are not numeric or alpha.  I've got a test string that is "Nissay Dowa General-Happy".  I need to change the string so that it becomes "NissayDowaGeneralHappy".  The JavaScript that I have created removes only the first space, resulting in "NissayDowa General-Happy".  The regular expression I am using is shown below.  Can someone tell me how to do it the right way, removing all spaces and the dash character?

    mystring = "Nissay Dowa General-Happy";

    regexp = /[^A-Za-z0-9]/;

    newstring = mystring.replace(regexp, "");

    alert(newstring);

    Gracias!

Risposte

Tutte le risposte