0

I'm trying to do a simple preg_match_all but don't get it running.

Following the code:

$regex= "get-/my/test/(?<{id1}>.*)/foo/(?<{f11}>.*)";
$template = "get-/my/test/hallo/foo/awwww123";


$match = preg_match_all("/".$regex."/",$template, $matches, PREG_SET_ORDER); 

var_dump($match);
var_dump($matches);

Executing the code I get the following error message:

E_WARNING : type 2 -- preg_match_all(): Unknown modifier 'y' -- at line 5

What I'm doing wrong?

My expectation is, that $match is true and $matches include the groups with names.

Update

Ok, I added the preg_quote but why is the following code not matching?

$regex= "get-/my/test/(?<{if1}>.*)/foo/(?<{tf4}>.*)";
$template = "get-/my/test/hallo/foo/werner12";
$regex = preg_quote($regex, "/");


$match = preg_match_all("|".$regex."|",$template, $matches, PREG_SET_ORDER); 

var_dump($match);
var_dump($matches);
SNO
  • 793
  • 1
  • 10
  • 30
  • use `preg_quote($regex,'/')` before using the regex. – Toto Apr 28 '20 at 15:45
  • If you're using `|` as delimoiter, don't use `preg_quote`. What are you trying to match with `(?<{id1}>.*)`? Remove the curly baces. – Toto Apr 28 '20 at 16:41

0 Answers0