-1

我有这样的代码注释块..

/**
 * 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 中的正则表达式来获取此评论,但每次都失败。任何人都可以为此建议一个正则表达式或任何其他解决方案来提取评论块。

4

3 回答 3

1

与您的第一个示例一样的注释块匹配的正则表达式是/\/\*\*[\s\S]*?\*\//. 提取整个评论后,您可以进行一些额外的解析。

于 2013-02-16T14:45:17.760 回答
1

我相信这就是你要找的。

  • 首先它寻找/**.
  • 然后它匹配评论中的任何内容,只要我们发现没有*/
  • 最后,它寻找一个*/结束

regexpal测试。

/\*{2}([^\*]|\*(?!/))*\*/
于 2013-02-16T15:39:25.517 回答
1

我假设您只是在寻找多行注释,这正是这样做的。

\/[*]+[\n\r][\s\S]+?[\n\r] *[*]+\/
于 2013-02-16T14:49:44.713 回答