我有像这样的代码评论块..
/**
* This method provide inheritance to the object supplied; this method inherit the
* public methods from the Parent class to the Child class. this also provide
* multiple inheritance, in which the method ambiguity is solved by the overriding
* the last inherited class's method.
* @access public
* @method inherit
* @param Object Parent
* @param Object Child
* @return Object
*/
并忽略
之类的评论/* This is a test comment for testing regex. */
我尝试了很多在javascript中使用正则表达式来获取此评论并且每次都失败了。任何人都可以建议使用这个或任何其他解决方案的正则表达式来提取注释块。
答案 0 :(得分:1)
与第一个示例匹配的注释阻止的正则表达式是/\/\*\*[\s\S]*?\*\//
。提取整个注释后,您可以进行一些额外的解析。
答案 1 :(得分:1)
我假设你只是在寻找多行注释,这里就是那个。
\/[*]+[\n\r][\s\S]+?[\n\r] *[*]+\/
答案 2 :(得分:1)
我相信这就是你要找的东西。
/**
。*/
*/
结束在regexpal进行了测试。
/\*{2}([^\*]|\*(?!/))*\*/