MySQL REGEXP matches a boundary word only but excluding the match in html tags

≡放荡痞女 提交于 2019-12-25 08:57:28

问题


Following this question and answer, I still have a bit trouble in the result I get,

For instance,

REGEXP '>[^<]*lau[[:>:]]' will match 'lau' only but not 'laurence' which is correct.

REGEXP '>[^<]*men[[:>:]]' will match 'empowerment' and 'women' which are not what I am after.

REGEXP '( |>|$)home( |<|$)' will match 'home' only but not 'home!' which it should.

How can match these correctly?

For instance,

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

It should not match any occurrence in html tags. home-town - not match


回答1:


how about REGEXP '>[^<]*[[:<:]]home[[:>:]]' ?

Besides, I am really interested in the performance of your solution... Why don't you have another column in your table, which contains the text having the html tags stripped. You are then able to make good use of the full text search, instead of having a complex regexp.



来源:https://stackoverflow.com/questions/11130353/mysql-regexp-matches-a-boundary-word-only-but-excluding-the-match-in-html-tags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!