replace any characters doesn't match with my regexp

replace any characters doesn't match with my regexp

i want to replace all of characters are not match with my string, for example i have:

  1.     <script>
  2.         var word = "my~wo@rd 12$3";
  3.         var regx = "/^[a-z0-9]+$/";
  4.         word = word.replace(eval(regx), '');
  5.     </script>

without any other regular expressions, how i can get this result:

  1. "myword123"