Why is the /pattern/ matching, but the RegExp not?
##content##
works!
##/content##
Problem is this line:
var r = new RegExp("##content##([\S\s]*?)##\/content##", "img");
It should be replaced with:
var r = new RegExp("##content##([\\S\\s]*?)##\/content##", "img");
Reason: Understand that RegExp object takes a String as argument to construct and you need to double escape \S
and \s
to be correctly interpreted by RegEx engine so \S
should become \\S
and \s should become \\s
in your regex.