【发布时间】:2014-12-10 06:48:10
【问题描述】:
我正在 Oracle 11g 数据库上使用 PL/SQL v10。
我有代码存储在我需要提取的问题表的描述列中。
为此,我正在制作正则表达式 which works fine in 101regex 但在 oracle 中失败,
我会假设我使用了不正确的语法。
select '''' || listagg(regexp_substr(q.questiondescription,'(LIF|LPA) ?\d{1,2}.\d{1,2}(\.\d{1})?'), ''', ''')
within group (order by q.questionid) || ''''
from question q
where q.isthunderheadonly = 0 or q.isthunderheadonly is null
我需要匹配的模式:
LIF 1.2 Both
LIF 2.7.1 Address Line 1
LIF 4.13 Occupation
LIF 10.6.1 Address Line 1
LPA0.1 What type of LPA do you want?
LPA0.2 Do you have same attorneys with your partner ?
我的正则表达式哪里出错了?
编辑:我得到的结果
'LIF 3.1', 'LIF 4.1', 'LIF 4.2', 'LIF 5.1', 'LIF 7.1', 'LPA0.1', 'LPA0.2'
我认为第二组之后它会忽略所有内容。
【问题讨论】:
-
你匹配什么,你不匹配什么?
(LIF|LPA)后面有一个空格,LPA0.1 What type of LPA do you want?中不存在该空格。 -
They were wrong@Avinash.
-
@vks 没飞,抱歉
-
@AvinashRaj 没有这样做
-
如果你想捕获所有然后在捕获组中包围模式regex101.com/r/dZ1vT6/15使用
\s*而不是`?`
标签: sql regex oracle oracle11g regexp-substr