Results 1 to 5 of 5
  1. #1

    js and replace()

    i need to replace all instance of any values of capital letters in the string content. however i cannot seem to get this to work. some examples of the code are:

    content = content.replace(/"[Word]"/gi,"[word]");
    content = content.replace(/"[\/Word]"/gi,"[\/word]");

    i donnot know too much about js, so sorry for any really obvious mistakes.
    workstations&servers @

  2. #2
    leave off the quotation marks and square brackets:

    content = content.replace(/Word/gi, "word");

    There's also String.toLowerCase:

    content = content.toLowerCase();

  3. #3
    well tolowercase wont work because i dont want the entire string to be lowercase. and i need the brackets because i may have a string
    i got [g] 2 dollars [/g] or something like that. so brackets defferientiate between [g] and the g in got.
    workstations&servers @

  4. #4
    ah, then you need to escape the brackets, because they have a special meaning in RegExps: content.replace(/\[Word\]/gi, "[word]"). This should lowercase all expressions inside square brackets:

    content.replace(/\[[^\]]+\]/gi, function(str) { return str.toLowerCase(); })

  5. #5
    yes once i did the \ before the brackets it all works perfectly thanks!
    workstations&servers @

Posting Permissions

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