Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Regex grouping - why is $ needed

mNemNov 15 2017 — edited Nov 15 2017

Hi,

Trying to figure out WHY the grouping match is not found for regex statements identified by 1 and 3 (highlighted in red) below. I am aware of no match for GRP2 in test cases 1 and 2. My concern is limited to the cells identified by -???- in the resultset.

- Learning purposes only -

with t (str) as

(

  select '00b11a22a' from dual

)

,regex (id,r) as

(

select 1,'^.*?b(.*)' from dual union 

select 2,'^.*?b(.*)$' from dual  union 

select 3,'^.*?b(.*?)a(.*)' from dual union 

select 4,'^.*?b(.*?)a(.*)$' from dual   

)

select

  r, id,

  regexp_substr(str, r, 1, 1, null, 1) grp1

, regexp_substr(str, r, 1, 1, null, 2) grp2

from t, regex

order by id;

R                        ID GRP1      GRP2   

---------------- ---------- --------- ---------

^.*?b(.*)                 1    -???-                

^.*?b(.*)$                2 11a22a            

^.*?b(.*?)a(.*)           3 11            -???-       

^.*?b(.*?)a(.*)$          4 11        22a     

SQL> select banner from v$version;

BANNER                                                                        

--------------------------------------------------------------------------------

Oracle Database 12c Standard Edition Release 12.1.0.2.0 - 64bit Production     

PL/SQL Release 12.1.0.2.0 - Production                                         

CORE    12.1.0.2.0    Production                                                       

TNS for Linux: Version 12.1.0.2.0 - Production                                 

NLSRTL Version 12.1.0.2.0 - Production 

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 13 2017
Added on Nov 15 2017
6 comments
1,667 views