I have a string that I'm trying to split into smaller strings at d+\/
(any number followed by a /
). Here is my string:
2/ This is a string
that has some words on a new line
3/ This is another string that might also have some words on a new line
So far i'm using this code:
$re = '/\d+\/\s+.*/';
$str = '2/ This is a string
that has some words on a new line
3/ This is another string that might also have some words on a new line';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
But the problem is that for the first match I'm getting only the first line:
[Match 1] 2/ This is a string
[Match 2] 3/ This is another string that might also have some words on a new line
How can I make every match to get all the lines up until d+\/
or up until the end of the full string/text?
Desired result:
[Match 1] 2/ This is a string that has some words on a new line
[Match 2] 3/ This is another string that might also have some words on a new line