My code in PHP generate a JSON based on the user input.
Inside this JSON, I have a Regex string "/regex/gi" with the delimiter.
I send this to the user and I would like javascript to test a string based on that regex. But since I have the delimiter inside the string, it does not work.
Sometime, I can receive the regex string as "regex", "/regex/" or "/regex/gi" So is there a way to remove thoses delimiter, or transform the string in a regex.
I tried to use "new RegExp" but it escape the string, and it won't work.
Here some code:
var json = {regex: "/hello/"}; //This code is generated by PHP
"hello".match(json.regex); //Test in javascript, not working, since the "/" are inside the regex and not used as delimiter
Anyone have an idea how I could do this?
Thank
/\/\//, user2 tries/\/\//giand user3\/\/(without delimiters). If we removed the/from the begin and the end, the third user will have a problem.