我一直在寻找"get everything but" regex questions,但我无法让它适用于我的情况。 我试图让除了结束评论*/
以外的所有内容。改进自定义正则表达式
我有这个表达式,得到的JavaScript函数的我声明:
/(\b(f|F)unction(.*?)\((.*?)\)\s*\{)/g
我就发现目前唯一的问题是,它也让我的东西,如:
function to do whatever */ function demo (el, hop) {
而不是
function demo (el, hop) {
当此函数声明带注释包含单词function
。
/** * recursive function to do whatever */ function demo (el, hop) { /*whatever*/ }
这是我试过至今没有结果:
/(\b(f|F)unction^((?!\*\/).)*?\((.*?)\)\s*\{)/g
这基本上是用什么建议in this post:
^((?!hede).)*$ //recommended
^((?!\*\/).)*? //mine
我在做什么错?
“这基本上是用在这篇文章有什么建议:”我建议你阅读其他的答案,特别是基准和ridgerunner的答案,因为你有选择最慢的方式。 –