0

I already looked at the Mozzila website and W3schools but couldn't find the answer

var someFunction = function (someString, someOtherString)
{
   if (someOtherString.match(someString))
   {
     someString = new RegExp(someString);
     someOtherString = someOtherString.replace(someString, "XXX");
     return someOtherString;
   }

   return null;
};

someFunction("dog", "dogeatdog");

Now I want the above RegExp to be applied globally but I don't know where/how to add the g character so that the above function call returns XXXeatXXX.

Any help would be appreciated!

1 Answer 1

1

Flags go in the second argument of the RegExp constructor, eg

new RegExp(someString, 'g')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.