Javascript RegEx Question
How to find below comment block(s) with ja开发者_开发问答vascript/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
Improving/Fixing a Regex for C style block comments
This is to match empty comment blocks :
^\s+/\*{1,}\n(^\s*\*{1,}\s*)+\*{1,}/
maybe this one could help you
/(\/\*[.\S\s]*?\*\/)/g
seem to be working
http://jsfiddle.net/WDhZP/
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 */
).
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 ;)
精彩评论