So I have a RegExp regex = /asd/
I am storing it as a as a key in my key-val store system.
So I say str = String(regex)
which returns "/asd/"
.
Now I need to convert that string back to a RegExp.
So I try: RegExp(str)
and I see //asd//
this is not what I want. It is not the same as /asd/
Should I just remove the first and last characters from the string before converting it to regex? That would get me the desired result in this situation, but wouldn't necessarily work if the RegExp had modifiers like /i
or /g
Is there a better way to do this?
See Question&Answers more detail:os