我如何編寫正則表達式來找到不是前面沒有單詞不是或不是的單詞壞。正則表達式排除,如果前面沒有或沒有
在下面我應該找到1號線和4號線
Line 1: a bad rider
Line 2 : apple is not bad
Line 3 : there is no bad remarks.
Line 4 : no there is nothing bad
的例子是有可能做到這一點不超前,因爲它沒有在Oracle SQL支持。
我如何編寫正則表達式來找到不是前面沒有單詞不是或不是的單詞壞。正則表達式排除,如果前面沒有或沒有
在下面我應該找到1號線和4號線
Line 1: a bad rider
Line 2 : apple is not bad
Line 3 : there is no bad remarks.
Line 4 : no there is nothing bad
的例子是有可能做到這一點不超前,因爲它沒有在Oracle SQL支持。
嘗試:
select *
from table
where regexp_like(column, 'bad') and NOT regexp_like(column, '(not|no) bad')
或只是(可能是最快的):
select *
from table
where column like('%bad%')
and not (column like '%not bad%' or column like '%no bad%');
再次感謝。它按預期工作。 – snowrock
添加更多測試數據!用句子說句「結不好?」。測試時,在您的非/非的兩側添加空格。對於這個問題「壞」,因爲它可能是另一個詞的一部分。 –
我相信這可以讓你更接近一點,允許時「不」或「壞」的一部分的另一個詞。正則表達式尋找一個空格,後跟字符串「不」或「否」,後跟空格,然後是「壞」,後跟空格或行尾(確保它們不是另一個單詞的一部分)。添加更多的測試短語,直到您確定!即您是否需要允許特殊字符,如第5行以問號結尾?
SQL> with tbl(data) as (
2 select 'Line 1: a bad rider' from dual union
3 select 'Line 2 : apple is not bad' from dual union
4 select 'Line 3 : there is no bad remarks.' from dual union
5 select 'Line 4 : no there is nothing bad' from dual union
6 select 'Line 5 : was that knot bad' from dual union
7 select 'Line 6 : let''s play badminton' from dual union
8 select 'Line 7 : let''s play no badminton' from dual
9 )
10 select *
11 from tbl
12 where not regexp_like(data, ' (not|no) bad(|$)');
DATA
---------------------------------
Line 1: a bad rider
Line 4 : no there is nothing bad
Line 5 : was that knot bad
Line 6 : let's play badminton
Line 7 : let's play no badminton
SQL>
使用['(?<!不)(?<!沒有)\ BBAD \ B'(https://regex101.com/r/ywMEV6/1) –
我需要做的是在甲骨文正規快遞。消極的前瞻似乎不被支持。是否有可能做到沒有負面看法? – snowrock
不,在純Oracle正則表達式中,這是不可能的。 –