www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17

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

  1. #16
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    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
    Posts
    3,767
    You can't avoid the constructer, but you can write it in one line.
    Code:
    inStr = inStr.replace(new RegExp(oldWordArr[i]+"/(?![^(]*\))","ig"), newWordArr[i]);
    Or maybe slightly clearer.
    Code:
    inStr = inStr.replace((new RegExp(oldWordArr[i]+"/(?![^(]*\))","ig")), newWordArr[i]);

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