Friday, 15 August 2014

regex - Javascript - replacing a word using regexp only if there's a space around it -


A small version of my code type looks like this:

  string = "test test Test Test Test Test "; Replacer = "test"; String = string.releast (new regxp ('+ +', 'gi'), "replaced");  

Now, I want to change one word only when it is around, this code really works well, but I am thinking that in my case a bottom RegExp ('\ s' + replacer + '\ s', 'gi')

Why do not you run it:

  RegExp ('\\ s' + replacer + '\\ s', 'gi')  

No comments:

Post a Comment