Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17

Thread: Replace characters: "Bob" to "John"

  1. #16
    Join Date
    Dec 2003
    Bucharest, ROMANIA
    Quote Originally Posted by massalexx View Post
    is it possible to avoid using regExp constructor so we can have a single line like this:
    inStr = inStr.replace(oldWordArr[i]+"/(?![^(]*\))/ig", newWordArr[i]);
    I am not sure if "ig" is allowed to be placed in there.
    By short: No.

  2. #17
    Join Date
    Aug 2007
    You can't avoid the constructer, but you can write it in one line.
    inStr = inStr.replace(new RegExp(oldWordArr[i]+"/(?![^(]*\))","ig"), newWordArr[i]);
    Or maybe slightly clearer.
    inStr = inStr.replace((new RegExp(oldWordArr[i]+"/(?![^(]*\))","ig")), newWordArr[i]);
    Great wit and madness are near allied, and fine a line their bounds divide.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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

Recent Articles