SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    replace not replacing all occurrences javascript

    Hey,

    I did this:

    var message = String(json.message).replace('/<br \/\>/g', '');

    and it's not replacing any of the <br /> found. I did do this:

    var message = String(json.message).replace('<br \/\>', '');

    And it replaced one of occurrences but not all of them.

    Anyone know what's going on?

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your replace expression is a string, and it is not finding any ''/<br \/\>/g"
    Lose the quotes to create a regular expression.

    You could also make it work in html as well as xhtml,
    by making it case-insensitive and optionally self closing-


    var message = String(json.message).replace(/<br *(\/)?>/gi, '');
    Last edited by mrhoo; Jul 11, 2010 at 16:57. Reason: commant


Bookmarks

Posting Permissions

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