I want to modify an invalid regex rather than throw an error, but I can't get the string of the invalid regex before the error is thrown...
var rex = /t(h)?u(?(1)r|e)sday/.replace(/\(\?\((\d)\)(.+?\|)(.+?)\)/g,'((?!\\$1)$2\\$1$3)').replace(/^\/|\/$/g,'')
This works, but is clearly not the solution I am looking for...
try{
var rex = /t(h)?u(?(1)r|e)sday/
} catch(e){
var rex = new RegExp(e.toString().split(/: /)[2].replace(/\(\?\((\d)\)(.+?\|)(.+?)\)/g,'((?!\\$1)$2\\$1$3)').replace(/^\/|\/$/g,''))
}
console.log(rex)
I want to be able to define the regex as a regex, not as a string. Can it be done?