I want to write a function that takes a string and returns an array with the content of all the block comments from it. For example:
var text = 'This is not a comment\n/*this is a comment*/\nNot a comment/*Another comment*/';
var comments = getComments(text);
And 'comments' will be an array with the values:
['this is a comment', 'Another comment']
I tried with this code:
function getComments(text) {
var comments,
comment,
regex;
comments = [];
regex = /\/\*([^\/\*]*)\*\//g;
comment = regex.exec(text);
while(comment !== null) {
skewer.log(comment);
comments.push(comment[1]);
comment = regex.exec(text);
}
return comments;
}
The problem is that if there is a * or a / inside the comment, it does not match