0

I need to find all backslashes in rows that start with "require_once" like these:

require_once $doc_root . "\inc\common.php";
require_once $doc_root . "\inc\admin_login.php";
require_once $doc_root . "\inc\usps_functions.php";
require_once $doc_root . '\lib\PDFMerger\PDFMerger.php';

I tried to use this one:

http://regex101.com/r/fP5fT5/1

HamZa
  • 13,530
  • 11
  • 51
  • 70
maykino
  • 11
  • 1
  • What do you want to do with it? What's the expected result/output? – Amal Murali Jul 11 '14 at 17:45
  • 2
    If you want to match the entire line, you can just use something like `^require_once \$doc_root \. (['"])\\([^"']+)\1;$`. [See demo](http://regex101.com/r/fP5fT5/2). (The `x` modifier isn't required.) – Amal Murali Jul 11 '14 at 17:48
  • I want to paste the reg expression in the Netbeans search function so it will find all backslashes and replace them with forwardslashles. – maykino Jul 11 '14 at 17:52

2 Answers2

0

Try:

^require_once.+[\\]+.*;$

For more information visit: http://regexpal.com/

JonatasTeixeira
  • 1,342
  • 1
  • 16
  • 24
  • If the goal is to capture the path, starting with the first `/`, then this regex is [incorrect](https://www.debuggex.com/r/hkfzVUqgfw16Ip-d) (I've added a group to highlight the problem). With the [greedy](http://stackoverflow.com/a/10764399) `.+`, it only captures the text following the *last* slash. It needs to be changed to reluctant: [`^require_once.+?[\\]+.*;$`](https://www.debuggex.com/r/66OEmoXvQ59OhBK4). (And actually, if the goal is to capture, it *should* contain those capture groups.) – aliteralmind Jul 11 '14 at 22:43
0

Use this:

(?m)(?:^require_once|(?<!^)\G)[^\\]*?\K\\

See demo on regex 101.

zx81
  • 38,175
  • 8
  • 76
  • 97