gpt4 book ai didi

php - 替换分号 (;),但不替换 html 字符(等)

转载 作者:行者123 更新时间:2023-12-02 18:25:40 25 4
gpt4 key购买 nike

我正在为我的问题寻找正则表达式。我有一个文本(产品规范),例如:

length: 20cm; height: 10cm; «Night» mode: yes; manufacturer : Sony© manual : yes

最终结果应该是这样的

<tr><td>length</td><td>20cm</td></tr>
...
<tr><td>manufacturer</td><td>Sony&copy;</td></tr>

所以我应该替换":" + whitespace characters(\s*)对于 "</td><td>"";" + whitespace characters(\s*)对于 "</td></tr><tr><td>" ,但在有拉丁符号 [a-z]+ 的情况下则不然和&; 之前签名。重点是在 html 字符中,例如 &_nbsp; &_laquo; &_copy 等包含“;”的

换句话说:\s*但不是&[a-z]+[;]

我该怎么做?

我在 smarty 中的正则表达式如下所示:"|regex_replace:"/[:]\s*/":""|regex_replace:"/[;]\s*/":"""所以唯一的就是删除 html 字符...我尝试了一些组合与 (?!...) 但没有成功我正在寻找这样的东西 RegExp for matching three letters, but not text "BUY"

最佳答案

使用负向后查找来查找分号编码字符的一部分:

(?<!&[a-z]{2})(?<!&[a-z]{3})(?<!&[a-z]{4})(?<!&[a-z]{5});\s*

此正则表达式仅匹配裸露的分号。不幸的是,需要多个后视,因此涵盖了由于负后视需要固定长度表达式而导致的所有可能性。

查看live demo这个正则表达式。

关于php - 替换分号 (;),但不替换 html 字符(等),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18402681/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com