Hi,
I’m looking at a way to strip comments out of a script text node.
This is where I’m at right now
var singleLineCom = /\\/{2}[\\s\\S]+?(?=\
)/g
var multiLineCom = /\\/\\*[\\s\\S]+?(?=\\*\\/)/g
An example of the multi line
/* Hopefully this script
will have the know how
to pick out various comments*/
/* and additonally these
following comments*/
Output
[“/* Hopefully this scrip…ck out various comments”, “/* and additonally these
following comments”]
As you can see I’m left with the starting /* and the newlines. I can obviously remove these on a separate pass, but would like to know if there’s a way to incorporate this into one regex.
I’ve tried /(?:\/\\s+)([\s\S]+?)(?=\\/)/ which get’s me closer, however as soon as I add the global modifier, the non-capture is ignored.
The single line similarly
Output
[“// like this one for instance”, “// Or this one”]
Cheers for any tips
RLM