I have the following
astring.replace(/(someregex/g, "replacementstring.$1")
I'd like to store it as some sort of object, so I can call it in the future. The obvious solution is to store it as two variables someregex and replacementstring and call it in the future as astring.replace(someregex, replacementstring + '.$1') But that seems really clunky to me.
Is there anyway to store the string replacement in a more concise manner? My current idea is to store .replace(/someregex/g, "replacementstring.$1") as a string called stringreplacement and use eval('astring' + stringreplacement). But that seems silly.
var pattern = new RegExp("someregex", "g");