oracle regexp_like: 将 Perl 正则表达式用于 AND 运算符等价物
oracle regexp_like: using Perl regexp for AND operator equivalent
在 Oracle REGEX_LIKE 中编写正则表达式时是否有等效的 AND 运算符?我一直在尝试 select 所有三个单词都必须包含在一个字符串中的情况。在下面的示例中,我想匹配 所有三个词、small & leather & 的所有实例goods 必须包含在字符串中。我试过很多在线正则表达式测试器,正则表达式语法完全符合我的需要,但是当我尝试在 REGEXP_LIKE 表达式中使用语法时,我得到零匹配
regexp_like(GLOBAL_CATEGORY,'(?=.*small)(?=.*leather)(?=.*goods)^.*$','i')
正则表达式测试程序示例可实现我正在寻找的内容: regexr.com/4vc1s
Men/Outerwear/Leather/Sale **(NO MATCH)**
Men > Accessories > Bags & Leather Goods > Small Leather Goods **(YES MATCH)**
Men > Accessories > Bags & Leather Goods > Bags **(NO MATCH)**
Men > Accessories > Bags & Leather Goods > Small Leather Goods **(YES MATCH)**
Men/Outerwear/Leather/Sale **(NO MATCH)**
Men/Small_Leather_Goods/Sale **(YES MATCH)**
Men/Outerwear/Leather **(NO MATCH)**
Men/Small_Leather_Goods **(YES MATCH)**
men>accessories>small>leather>goods **(YES MATCH)**
如果您不坚持使用正则表达式,那么简单的 instr 就可以完成工作:
SQL> with test (col) as (
2 select 'Men/Outerwear/Leather/Sale **(NO MATCH)**' from dual union all
3 select 'Men > Accessories > Bags & Leather Goods > Small Leather Goods **(YES MATCH)**' from dual union all
4 select 'Men > Accessories > Bags & Leather Goods > Bags **(NO MATCH)**' from dual union all
5 select 'Men > Accessories > Bags & Leather Goods > Small Leather Goods **(YES MATCH)**' from dual union all
6 select 'Men/Outerwear/Leather/Sale **(NO MATCH)**' from dual union all
7 select 'Men/Small_Leather_Goods/Sale **(YES MATCH)**' from dual union all
8 select 'Men/Outerwear/Leather **(NO MATCH)**' from dual union all
9 select 'Men/Small_Leather_Goods **(YES MATCH)**' from dual union all
10 select 'men>accessories>small>leather>goods **(YES MATCH)**' from dual
11 )
12 select * from test
13 where instr(lower(col), 'small') > 0
14 and instr(lower(col), 'leather') > 0
15 and instr(lower(col), 'goods') > 0;
COL
------------------------------------------------------------------------------
Men > Accessories > Bags & Leather Goods > Small Leather Goods **(YES MATCH)**
Men > Accessories > Bags & Leather Goods > Small Leather Goods **(YES MATCH)**
Men/Small_Leather_Goods/Sale **(YES MATCH)**
Men/Small_Leather_Goods **(YES MATCH)**
men>accessories>small>leather>goods **(YES MATCH)**
SQL>
(是的,我知道,(YES/NO MATCH)
不是字符串的一部分,但我懒得删除它。)
假设您想要 small、leather 和 goods 的顺序,请尝试:
regexp_like(GLOBAL_CATEGORY,'*small.*.leather.*goods*', 'i')
。 匹配任何字符
* 匹配零次或多次出现的前面的子表达式
i 是一个匹配模式,指定不区分大小写匹配
Demo这里
在 Oracle REGEX_LIKE 中编写正则表达式时是否有等效的 AND 运算符?我一直在尝试 select 所有三个单词都必须包含在一个字符串中的情况。在下面的示例中,我想匹配 所有三个词、small & leather & 的所有实例goods 必须包含在字符串中。我试过很多在线正则表达式测试器,正则表达式语法完全符合我的需要,但是当我尝试在 REGEXP_LIKE 表达式中使用语法时,我得到零匹配
regexp_like(GLOBAL_CATEGORY,'(?=.*small)(?=.*leather)(?=.*goods)^.*$','i')
正则表达式测试程序示例可实现我正在寻找的内容: regexr.com/4vc1s
Men/Outerwear/Leather/Sale **(NO MATCH)**
Men > Accessories > Bags & Leather Goods > Small Leather Goods **(YES MATCH)**
Men > Accessories > Bags & Leather Goods > Bags **(NO MATCH)**
Men > Accessories > Bags & Leather Goods > Small Leather Goods **(YES MATCH)**
Men/Outerwear/Leather/Sale **(NO MATCH)**
Men/Small_Leather_Goods/Sale **(YES MATCH)**
Men/Outerwear/Leather **(NO MATCH)**
Men/Small_Leather_Goods **(YES MATCH)**
men>accessories>small>leather>goods **(YES MATCH)**
如果您不坚持使用正则表达式,那么简单的 instr 就可以完成工作:
SQL> with test (col) as (
2 select 'Men/Outerwear/Leather/Sale **(NO MATCH)**' from dual union all
3 select 'Men > Accessories > Bags & Leather Goods > Small Leather Goods **(YES MATCH)**' from dual union all
4 select 'Men > Accessories > Bags & Leather Goods > Bags **(NO MATCH)**' from dual union all
5 select 'Men > Accessories > Bags & Leather Goods > Small Leather Goods **(YES MATCH)**' from dual union all
6 select 'Men/Outerwear/Leather/Sale **(NO MATCH)**' from dual union all
7 select 'Men/Small_Leather_Goods/Sale **(YES MATCH)**' from dual union all
8 select 'Men/Outerwear/Leather **(NO MATCH)**' from dual union all
9 select 'Men/Small_Leather_Goods **(YES MATCH)**' from dual union all
10 select 'men>accessories>small>leather>goods **(YES MATCH)**' from dual
11 )
12 select * from test
13 where instr(lower(col), 'small') > 0
14 and instr(lower(col), 'leather') > 0
15 and instr(lower(col), 'goods') > 0;
COL
------------------------------------------------------------------------------
Men > Accessories > Bags & Leather Goods > Small Leather Goods **(YES MATCH)**
Men > Accessories > Bags & Leather Goods > Small Leather Goods **(YES MATCH)**
Men/Small_Leather_Goods/Sale **(YES MATCH)**
Men/Small_Leather_Goods **(YES MATCH)**
men>accessories>small>leather>goods **(YES MATCH)**
SQL>
(是的,我知道,(YES/NO MATCH)
不是字符串的一部分,但我懒得删除它。)
假设您想要 small、leather 和 goods 的顺序,请尝试:
regexp_like(GLOBAL_CATEGORY,'*small.*.leather.*goods*', 'i')
。 匹配任何字符
* 匹配零次或多次出现的前面的子表达式
i 是一个匹配模式,指定不区分大小写匹配
Demo这里