0

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>
Gumbo
  • 643,351
  • 109
  • 780
  • 844
Nate Imus
  • 253
  • 1
  • 3
  • 10
  • 1
    Parenthesises in regex are reserved characters, so you need to escape them to `\(` and `\)`. `(require|include)(_once)?\([^\)]+\)` – h2ooooooo Jan 19 '14 at 14:20
  • I understand that I need to escape to check for them but i need to to do sort of an if statement...if it has parentheses or it doesn't – Nate Imus Jan 19 '14 at 14:21

1 Answers1

1

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)

Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125
  • 1
    I think you need to test for semicolon... the following `require_once a;require_once b;` matches `require_once a;require_once` – George Reith Jan 19 '14 at 14:28