I have really strange issue with regex, I am testing using LINK Please only test there as it works exactly the same as on my machine. I should be able only to see following text: "Audit Note by 3 4 5 6 7" But I can see an empty array. I know that this code works on regex101.com Please help
$string = "1
2
Audit Note by 3
4
5
6
7
I don't need this line
I don't need this line
";
preg_match("/^Audit Note by(.*$)^$/ms",$string, $nmatch);
echo $nmatch[0];
Rather than using ^$
to match a new line you can use \R
and use this code:
$string = "1
2
Audit Note by 3
4
5
6
7
I don't need this line
I don't need this line
";
preg_match('/^(Audit Note by.*?)\R\R/ms',$string, $nmatch);
echo $nmatch[1];
\R\R
matches 2 consecutive line breaks of any type.
Output:
Audit Note by 3
4
5
6
Try this regex:
preg_match("/Audit Note by (\d+\s+)+/",$string, $nmatch);
echo $nmatch[0];
It gives me:
Audit Note by 3 4 5 6 7
Here's your updated regex: https://regex101.com/r/sSg4gb/7
$string = "1
2
Audit Note by 3
4
5
6
7
I don't need this line
I don't need this line
";
preg_match("#Audit Note by [\d.\s]*#",$string, $nmatch);
echo($nmatch[0]);
This outputs:
Audit Note by 3
4
5
6
7
Check it out here: https://3v4l.org/hiXpY