Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我读了这个PHP RegEx page,但要么我遗漏了一些东西,误读了一些东西,要么它不像他们说的那样工作。我猜这是前两个之一。
$str = preg_replace("([|]\d*)", "\1;", $str);
您的正则表达式应该遵循 Perl 语法,这意味着它必须以相同的字符开头和结尾(有一些例外)。此外,后向引用应该以双斜杠开头,以避免 PHP 的双重转义。这应该有效(通过快速测试):
$str = "asdfasdf |123123 asdf iakds |302 asdf |11"; $str = preg_replace("/([|]\d*)/", "\\1;", $str); echo $str; // prints "asdfasdf |123123; asdf iakds |302; asdf |11;"