-2

I have the following code :

$data = "numbers{One
Two
Three}";

preg_match("~(?<=numbers{)(.*?)(?=})~", $data, $result);
echo $result[0];

The preg_match doesn't work i don't know why if the data is just one line then it works

2 Answers2

-1

all regex engines suport many search modificators, like for caseInsensitive serch or multiLineSourse, try "m" modificator

preg_match("~(?<=numbers{)(.*?)(?=})~ms", $data, $result);
-1

The . doesn't match a newline use the s modifier:

~(?<=numbers{)(.*?)(?=})~s

Or you could just match on NOT }:

~(?<=numbers{)([^}]*)(?=})~

Not knowing all of you requirements, you may be able to simplify it:

preg_match("~numbers{([^}]*)}~", $data, $result);
echo $result[1];
AbraCadaver
  • 78,200
  • 7
  • 66
  • 87