My regex must match what's within /* @DT-HIDE / and / @/DT-HIDE */. It's fine until a page contains two blocks.
If there are two blocks, well, $1 will match all that's between the first opening @DT-HIDE and last @/DT-HIDE. I suppose it's about a greedy * instead of an ? but I can't figure it out.
Regex:
const pattern = new RegExp(/(\/\*\s@DT-HIDE\s\*\/) ([\s\S]*?) (\/\*\s@\/DT-HIDE\s\*\/)/g);
Example value being processed:
/* @DT-HIDE */
function(){
return "...";
}
/* @/DT-HIDE */
/* @DT-HIDE */
function logic(url){
return new Promise( (resolve, reject) => {
...
});
}
/* @/DT-HIDE */
new RegExp()constructor, it's a shame you don't pass it a string rather than a/.../construct : you would avoid having to escape slashes inside the regexp. You would instead need to escape double-quotes, which wouldn't be a problem in your case./(\/\*\s@DT-HIDE\s\*\/)([\s\S]*?)(\/\*\s@\/DT-HIDE\s\*\/)/g. Also you don't need the constructor simply assign the regex to thepatternvariable/.../constructs