Question

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>
Was it helpful?

Solution

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top