0

我正在 Oracle 11g 数据库上使用 PL/SQL v10。
我有代码存储在我需要提取的问题表的描述列中。为此,我正在努力生成在 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'

我认为它忽略了第二组之后的所有内容。

4

2 回答 2

2
(LIF |LPA)\d{1,2}(.\d{1,2})*(\.\d{1})?

或者

(LIF |LPA)[([:digit:]|.)]*

这将匹配。

演示:

SQL> l
  1  with my_data(str,num) as
  2  (
  3  select 'LIF 1.1.1 First Name',1 from dual
  4  union all
  5  select 'LIF 1.2 Date Of Birth' ,1 from dual
  6  union all
  7  select 'LIF 1.2 Date Of Birth' ,2 from dual
  8  union all
  9  select 'LIF 7.10 How many other properties do you own?',1 from dual
 10  union all
 11  select 'DT 05. Do you have children?',1 from dual
 12  union all
 13  select 'LIF 15 Notes to solicitor',1  from dual
 14  union all
 15  SELECT 'LPA0.2 Do you have same attorneys with your partner' ,1 from dual
 16  )
 17  select str, regexp_substr(str,'(LIF |LPA)\d{1,2}(.\d{1,2})*(\.\d{1})*') regex1,
 18  regexp_substr(str,'(LIF |LPA)[([:digit:]|.)]*') regex2
 19  from my_data
 20* group by str
SQL> /

STR                                                          REGEX1               REGEX2
------------------------------------------------------------ ---------------------------
LPA0.2 Do you have same attorneys with your partner          LPA0.2               LPA0.2
DT 05. Do you have children?
LIF 1.1.1 First Name                                         LIF 1.1.1            LIF 1.1.1
LIF 1.2 Date Of Birth                                        LIF 1.2              LIF 1.2
LIF 15 Notes to solicitor                                    LIF 15               LIF 15
LIF 7.10 How many other properties do you own?               LIF 7.10             LIF 7.10

6 rows selected.
于 2014-10-15T09:26:11.587 回答
1

I change the Regex so hope it can work fine on your oracle :)

L(IF|PA\d{1,}(\.\d{1,}){0,1}) {1,}(\d{1,}(\.\d{1,}){0,}){0,1}

Regular expression visualization

Debuggex Demo

于 2014-10-15T09:01:16.797 回答