I'm trying to use grunt-string-replace to replace the contents of a file between 2 HTML comments. What I have come up with works fine over a single line but for the life of me, I cannot get it to match where there are multiple lines.
<!-- START COMMENT -->This matches<!-- END COMMENT -->
<!-- START COMMENT -->
this
doesn't
match
<!-- END COMMENT -->
My regex I have currently is
/<!-- START COMMENT -->[\s\S]*?<!-- END COMMENT -->/g
I understood that replacing the .*?
(which worked for a single line) with [\s\S]*?
would allow a match over multiple lines but I can't seem to get it to work.
Anyone have any ideas?
Update: As commenters below mentioned, my regex was fine, it was how I was implementing it with grunt
//This didn't work
.....
options:{
replacements: [
{
pattern: "/<!-- START COMMENT -->[\s\S]*?<!-- END COMMENT -->/g",
replacement: '<script src="'+minJSDestination+'"></script>'
}
]
}
.....
//This does work
.....
options:{
replacements: [
{
pattern: /<!-- START COMMENT -->([\s\S]*?)<!-- END COMMENT -->/ig,
replacement: '<script src="'+minJSDestination+'"></script>'
}
]
}
.....