Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Apr 2006
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Replace ampersand with regular expression. Special Characters

    Hi, I would like to remove ampersands from text and repace them with the HTML special character.

    This is so that I can use them in a query string.

    This is my code but it doesn't work, can you see a problem with it?

    //if have needed to escape the string for previous operations

    textarea.value=unescape(textarea.value);
    content = textarea.value;
    content = content.replace("&","&");

    Thanks in advance

    Jon

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,017
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    content = content.replace(/&/g,"&");


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •