Are there any potential pitfalls or limitations when using regular expressions in PHP to search for specific expressions like "http" and "mailto"?

When using regular expressions in PHP to search for specific expressions like "http" and "mailto", one potential pitfall is that these expressions may occur within larger strings, potentially leading to false positives. To avoid this, you can use word boundaries (\b) in your regular expressions to ensure that the search terms are matched as whole words.

$string = "Visit my website at http://example.com or email me at mailto:info@example.com";
$pattern = '/\b(http|mailto)\b/';
if (preg_match($pattern, $string)) {
    echo "Match found!";
} else {
    echo "No match found.";
}