【问题标题】:MySQL REGEXP matches a boundary word only but excluding the match in html tagsMySQL REGEXP 仅匹配边界词,但不包括 html 标签中的匹配
【发布时间】:2012-06-23 05:26:48
【问题描述】:

按照这个question and answer,我得到的结果还是有点麻烦,

例如,

REGEXP '>[^<]*lau[[:>:]]' 将只匹配 'lau' 而不是 'laurence' 这是正确的。

REGEXP '>[^<]*men[[:>:]]' 将匹配 'empowerment' 和 'women' 这不是我所追求的。

REGEXP '( |>|$)home( |<|$)' 将仅匹配 'home' 而不是它应该的 'home!'。

如何正确匹配这些?

例如,

Home - match
HOME - match
welcome home! - match
home is far! - match
hometown - not match
xxhomexx - not match
<a href="home.html">Hello</a> - not match
<p class="home">a box</p> - not match

它应该匹配 html 标记中的任何出现。 家乡 - 不匹配

【问题讨论】:

    标签: php mysql sql regex word-boundary


    【解决方案1】:

    怎么样 正则表达式 '>[^:]]' ?

    此外,我对您的解决方案的性能非常感兴趣...为什么不在您的表格中添加另一列,其中包含去除了 html 标记的文本。然后,您就可以充分利用全文搜索,而不是使用复杂的正则表达式。

    【讨论】:

    • Why don't you have another column in your table, which contains the text having the html tags stripped. 我从没想过这个......但REGEXP '&gt;[^&lt;]*[[:&lt;:]]home[[:&gt;:]] 似乎工作正常。谢谢。
    猜你喜欢
    • 2012-06-22
    • 2011-12-21
    • 2017-02-11
    • 1970-01-01
    • 1970-01-01
    • 2013-08-07
    • 1970-01-01
    • 2020-12-02
    • 2016-02-19
    相关资源
    最近更新 更多