cancel
Showing results for 
Search instead for 
Did you mean: 

Replace All Case Insensitive Based on Incoming Value

ronmwhite
New Contributor II

Hello. I am having some issues getting “replace” to work the way I want; kindly have a look.

This works:
$Name.replace(/ron/gi, “Ronald”)

So does this:
$Name.replace($OldName, $NewName)

But, I want the above to also work with the “gi” option but it does not, e.g.:

$Name.replace(/$OldName/gi, $NewName)

Has anyone handled this before? If so, kindly share your solution. Thanks.

1 ACCEPTED SOLUTION

del
Contributor III

There may be a better option, but eval will probably work:

eval("$Name.replace(/" + $OldName + "/gi,$NewName)")

View solution in original post

2 REPLIES 2

del
Contributor III

There may be a better option, but eval will probably work:

eval("$Name.replace(/" + $OldName + "/gi,$NewName)")

ronmwhite
New Contributor II

That will work @del . Thanks for the tip.