2

The code:

  preg_match("/(\/.*?\/)((?:[^\/]|\\\/)+?)(?:(?<!\\)\s|$)/", $line, $matches);

Code tested at: http://www.phpliveregex.com/p/ivO

On my local I get:

preg_match(): Unknown modifier ')'

PHP 5.6.26

Codium
  • 3,200
  • 6
  • 34
  • 60

1 Answers1

4

The main issue is that you failed to properly escape the backslash. You need four backslashes to match a literal backslash in a PHP string literal. Also, if your pattern contains so many backslashes you should think of using a different regex delimiter.

I suggest

 preg_match("~(/.*?/)((?:[^/]|\\\\/)+?)(?:(?<!\\\\)\s|$)~", $line, $matches);

The tilde as a regex delimiter will make the pattern cleaner since there is no longer need to escape backslashes.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563