查找带括号和不带括号的“require”(Find “require” with and without parentheses)

编程入门 行业动态 更新时间:2024-10-27 14:30:16
查找带括号和不带括号的“require”(Find “require” with and without parentheses)

到目前为止我有这个:

(require|include)(_once)?\(([^)]+)

它检查所有require,require_once,include和include_once,但它需要采用以下格式:

require(FOO)

我还需要找到:

require FOO

所以它需要考虑括号和不带括号以及第二个例子中的空间。

完整代码的样式将是:

<search position="replace" regex="true"><![CDATA[~(require|include)(_once)?\(([^)]+)~]]></search> <add><![CDATA[$1$2(VQMod::modCheck($3)]]></add>

So far i have this:

(require|include)(_once)?\(([^)]+)

which it checks for all require, require_once, include and include_once but it requires to be in the format of:

require(FOO)

I need to also find:

require FOO

so it needs to take into consideration with and without parentheses as well as the space that would be in the second example.

a style of the full code would be:

<search position="replace" regex="true"><![CDATA[~(require|include)(_once)?\(([^)]+)~]]></search> <add><![CDATA[$1$2(VQMod::modCheck($3)]]></add>

最满意答案

您可以使用分支重置:( (?|...|...)

(require|include)(_once)?(?|\(([^)]+)\)| ([^\s;]+))

分支重置功能的主要兴趣在于内部的捕获组具有相同的编号。

根据George Reith的评论,你必须找到非括号案例的好字符类。 如果遇到白色空格或分号,我选择[^\s;]来停止。

另一种方式:( 我不在乎是否有括号)

(require|include)(_once)?[( ]([^\s;)]+)

另一种方式:( 如果那么其他)

(require|include)(_once)?(\()?(?(3)| )([^\s;)]+)

(对于最后一种方式,请注意文件名在组4中)

You can use a branch reset: (?|...|...)

(require|include)(_once)?(?|\(([^)]+)\)| ([^\s;]+))

The main interest of the branch reset feature is that the capture groups inside have the same number.

According to George Reith comment, you must find the good character class for the non-parenthesis case. Here I have choosen [^\s;] to stop if a white-space or a semi-colon is encountered.

An other way: (I don't care if there are parenthesis or not)

(require|include)(_once)?[( ]([^\s;)]+)

An other way: (If Then else)

(require|include)(_once)?(\()?(?(3)| )([^\s;)]+)

(For this last way, note that the file name is in group 4)

更多推荐

本文发布于:2023-07-31 00:07:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340289.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:括号   不带   require   Find   parentheses

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!