What are the potential limitations when trying to output sentences starting with a specific word in PHP?

When trying to output sentences starting with a specific word in PHP, a potential limitation is that it may be difficult to ensure that the word is always at the beginning of the sentence due to variations in punctuation and spacing. One way to solve this is by using regular expressions to match the specific word at the beginning of the sentence, regardless of punctuation or spacing.

$sentences = "Hello, world! This is a sample sentence starting with the word hello. Another sentence starting with hello.";

$word = "hello";

preg_match_all('/\b' . $word . '\b[^.!?]*[.!?]/i', $sentences, $matches);

foreach ($matches[0] as $sentence) {
    echo $sentence . "<br>";
}