我在MySQL中有一個sql查詢,我想要一個與'<'和'>'之間的字符串不匹配的表達式。例如:正則表達式匹配MySQL中的html標籤之外的文本
select '<span class="boldtext">collaboratively site</span> – regardless of platform or language' rlike 'expression looking for boldtext' ==> should return false because 'boldtext' locates inside a html tag
select '<span class="boldtext">collaboratively site</span> – regardless of platform or language' rlike 'expression looking for platform' ==> should return true because 'platform' locates outside a html tag
我試過下面但沒有運氣。我猜是因爲'*'很貪婪。
select '...' rlike '[^[.<.]]?[^[.>.]]*platform[^[.<.]]*[^[.>.]]?' # This expression doesn't work
我知道,表達會像下面,如果是在編程語言像Ruby或PHP
'<span class="boldtext">collaboratively site</span> – regardless of platform or language' =~ /((?!<[^>]*))\bboldtext\1/ # => false
'<span class="boldtext">collaboratively site</span> – regardless of platform or language' =~ /((?!<[^>]*))\bplatform\1/ # => true
運行我發現了一個similar post但我不能把它改寫了我的情況。
你能幫助我如何拿出匹配字符串的表達式,而不是在html標籤裏面(在mysql裏運行)?
這裏的答案對我有用[MySQL REGEXP僅匹配邊界字,但不包括html標籤中的匹配項](https://stackoverflow.com/a/11130498/2277851) – 2017-05-26 14:34:06