How can one ensure that specific words are prioritized in a regex pattern in PHP?

When creating a regex pattern in PHP, you can ensure that specific words are prioritized by using the pipe symbol "|" to separate the words in order of priority. This way, the regex engine will match the words in the order they are listed, giving priority to the first word.

$pattern = "/word1|word2|word3/";
$string = "This is a sentence with word2 in it.";

if (preg_match($pattern, $string)) {
    echo "Match found!";
} else {
    echo "No match found.";
}