What are the potential pitfalls of using regular expressions to parse PHP code in a CMS?

One potential pitfall of using regular expressions to parse PHP code in a CMS is that they may not be able to accurately handle all possible variations of PHP syntax, leading to parsing errors or incorrect results. To solve this issue, a more robust parsing method, such as using a PHP parser library or built-in PHP functions like token_get_all(), should be considered.

// Example of using token_get_all() to parse PHP code in a CMS
$phpCode = '<?php echo "Hello, World!"; ?>';
$tokens = token_get_all($phpCode);

foreach ($tokens as $token) {
    if (is_array($token)) {
        echo token_name($token[0]) . ": " . $token[1] . PHP_EOL;
    } else {
        echo $token . PHP_EOL;
    }
}