Html/xml should not be processed with regular expressions, it is really hard to generate one that will match anything. But you can use the builtin dom extension and process your string recursively:# Warning: untested code!function process($node, $replaceRules) { foreach ($node->children as $childNode) { if ($childNode instanceof DOMTextNode) { $text = pre_replace( array_keys(replaceRules), array_values($replaceRules), $childNode->wholeText ); $node->replaceChild($childNode, new DOMTextNode($text)); } else { process($childNode, $replaceRules); } }}$replaceRules = array( '/\bcolor\b/i' => 'colour', '/\bmeter\b/i' => 'metre',);$doc = new DOMDocument();$doc->loadHtml($htmlString);process($doc, $replaceRules);$htmlString = $doc->saveHTML(); 这篇关于我需要什么正则表达式模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-11 02:27