Hello,
How to find below comment block(s) with javascript/jquery regex:
/*
some description here
*/
It may even look like:
/* some description here
*/
Or
/* some description here */
Hello,
How to find below comment block(s) with javascript/jquery regex:
/*
some description here
*/
It may even look like:
/* some description here
*/
Or
/* some description here */
With php I think it would be :
$pattern='/\/\*.*?/*///';
or
$pattern='/\*[^*]*\*+([^/*][^*]*\*+)*/
';
chk this out
http://stackoverflow.com/questions/462843/improving-fixing-a-regex-for-c-style-block-comments
This is to match empty comment blocks :
^\s+/\*{1,}\n(^\s*\*{1,}\s*)+\*{1,}/
var match = myString.match(/\/\*([\w\W]*)\*\//)
If match !== null
, match[0]
will contain the comment, and match[1]
will contain the comment without the comment delimiters.
edit: it's multiline now ;)
Here's an actual Javascript answer:
var commentRegex = /\/\*([^/]|\/[^*])*\*\//;
If you need a version that checks to see whether an entire string is a comment:
var completeCommentRegex = /^\/\*([^/]|\/[^*])*\*\/$/m;
Explanation: the regex matches a leading /*
, followed by any number of either individual characters other than "/", or "/" followed by anything not an asterisk, and then finally the closing */
. The "m" flag in the second version ensures that embedded newlines won't mess up the "^" and "$" anchors.
Finally, if you actually want the comment text, you'd add an appropriate parenthesized block in there (after the /*
and before the */
).