문제

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>
도움이 되었습니까?

해결책

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)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top