How can the use of regular expressions in PHP be optimized for efficiency and accuracy?

Using regular expressions in PHP can be optimized for efficiency and accuracy by compiling the regular expression pattern only once and reusing it for multiple matches. This can be achieved by using the `preg_match()` function with the `PREG_OFFSET_CAPTURE` flag to get the offset of the matched substring. Additionally, using specific quantifiers and anchors in the regular expression pattern can help improve accuracy and efficiency.

$pattern = '/\b(\w+)\b/';
$string = 'This is a sample string with multiple words.';
if (preg_match_all($pattern, $string, $matches, PREG_OFFSET_CAPTURE)) {
    foreach ($matches[1] as $match) {
        echo "Word: {$match[0]}, Offset: {$match[1]}\n";
    }
}