我的 PHP 代码中有以下正则表达式:
// markers for italic set *Text*
if (substr_count($line, '*')>=2)
{
$line = preg_replace('#\*{1}(.*?)\*{1}#', '$1', $line);
}
效果很好。
但是,当 $line 持有 时,例如
*This is my text
* Some other text
然后正则表达式仍然考虑文本并将其转换为:
This is my text
Some other text
目标是如果遇到 则不翻译文本。如何使用正则表达式来做到这一点 - 使用所谓的“负向前瞻”或者如何更改现有的正则表达式?
注意:类似 *This is my text* 的字符串仍应考虑和转换。
Some other text
和再次 *italic*
END
想法:或者我应该分解 $line 然后使用正则表达式迭代结果?!
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号