This is a simplified example, but when I run this code the first does not match as it should. It only matches the first part and nothing else. The other two occurrences match properly so I have no idea why the first wouldn't.
$str = 'What is 5 plus three?What is 4 plus three?What is 4 plus two?';
$replacees = [
'/What is (.*?) plus two\?/',
'/What is (.*?) plus three\?/',
];
$replacers = [
'I know $1 and 2.',
'I know $1 and 3.',
];
print_r( preg_replace($replacees, $replacers, $str) );
The results from that are:
I know 5 plus three?I know 4 and 3.What is 4 and 2.
But I'm expecting:
I know 5 and 3.I know 4 and 3.I know 4 and 2.
.*?will match all the string until "plus two?".