I am refactoring a series of RegExp a/b patterns that are used in two ways.
One uses the ^
as the third character.
/[^a-zA-Z0-9,?@&!#'"~ _;\.\*\/\-\+ ]/
The other doesn't use the ^
/[a-zA-Z0-9,?@&!#'"~ _;\.\*\/\-\+ ]/
Rather than write this pattern in two way is there a way to write it once and add the ^
to a second version?
This throws an error but as an example is there something available like this?
varOne = /[a-zA-Z0-9,?@&!#'"~ _;\.\*\/\-\+ ]/
varTwo = [varOne.slice(0, 1), '^', varOne.slice(1)].join('')