dbTalk Databases Forums  

REGEXP_REPLACE doesn't comply with the standard, does it ?

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss REGEXP_REPLACE doesn't comply with the standard, does it ? in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Spendius
 
Posts: n/a

Default REGEXP_REPLACE doesn't comply with the standard, does it ? - 06-29-2010 , 07:06 AM






Hi,

The following works *everywhere* I've ran it:
$ echo rbcde_fghijkl_mnopq|sed "s/_\([a-z]\)/\u\1/g"
rbcdeFghijklMnopq

(in vi, at several Unix prompts...: I want to replace letters that
come after an underscore by their uppercase value, and get
rid of this underscore)

I've found no way to have the same behaviour using REGEXP_REPLACE:
SQL> select regexp_replace('rbcde_fghijkl_mnopq','_\([a-z]\)','\u\1')
from dual;
REGEXP_REPLACE('RBC
-------------------
rbcde_fghijkl_mnopq

How can you then obtain in SQL what I'm getting above in Ux ?

Thanks.
Spendius

Reply With Quote
  #2  
Old   
Vladimir M. Zakharychev
 
Posts: n/a

Default Re: REGEXP_REPLACE doesn't comply with the standard, does it ? - 06-29-2010 , 01:04 PM






On Jun 29, 4:06*pm, Spendius <spend... (AT) muchomail (DOT) com> wrote:
Quote:
Hi,

The following works *everywhere* I've ran it:
$ echo rbcde_fghijkl_mnopq|sed "s/_\([a-z]\)/\u\1/g"
rbcdeFghijklMnopq

(in vi, at several Unix prompts...: I want to replace letters that
come after an underscore by their uppercase value, and get
rid of this underscore)

I've found no way to have the same behaviour using REGEXP_REPLACE:
SQL> select regexp_replace('rbcde_fghijkl_mnopq','_\([a-z]\)','\u\1')
from dual;
REGEXP_REPLACE('RBC
-------------------
rbcde_fghijkl_mnopq

How can you then obtain in SQL what I'm getting above in Ux ?

Thanks.
Spendius
Well, not every RE engine supports these escape sequences as they are
actually not 'standard'. Most Perl-derived do, but POSIX standard for
RE does not define them and Oracle's implementation conforms to POSIX
with just a few Perl-influenced extensions. Unfortunately, \U, \u, \L
and \l are not among them. And there seem to be no way to do what you
want with REGEXP_REPLACE, at least I don't see how it can be achieved.
Java Pattern class does not support these escapes, too, so you can't
even resort to built-in Java VM.

You might submit an enhancement request to Oracle and ask them to
implement these escapes, but my experience with Oracle ERs suggests
that even if they will consider it for implementation we are unlikely
to see it actually implemented until R12.2.


Regards,
Vladimir M. Zakharychev

Reply With Quote
  #3  
Old   
joel garry
 
Posts: n/a

Default Re: REGEXP_REPLACE doesn't comply with the standard, does it ? - 06-29-2010 , 03:44 PM



On Jun 29, 5:06*am, Spendius <spend... (AT) muchomail (DOT) com> wrote:
Quote:
Hi,

The following works *everywhere* I've ran it:
$ echo rbcde_fghijkl_mnopq|sed "s/_\([a-z]\)/\u\1/g"
rbcdeFghijklMnopq

(in vi, at several Unix prompts...: I want to replace letters that
come after an underscore by their uppercase value, and get
rid of this underscore)

I've found no way to have the same behaviour using REGEXP_REPLACE:
SQL> select regexp_replace('rbcde_fghijkl_mnopq','_\([a-z]\)','\u\1')
from dual;
REGEXP_REPLACE('RBC
-------------------
rbcde_fghijkl_mnopq

How can you then obtain in SQL what I'm getting above in Ux ?

Thanks.
Spendius
Well, initcap seems to work with underscores, then you get rid of the
underscores?

1 select
replace(replace(initcap('dummy'||'rbcde_fghijkl_mn opq'),'_',''),'Dummy','')
2* from dual
JEG@TTST> /

REPLACE(REPLACE(I
-----------------
rbcdeFghijklMnopq

jg
--
@home.com is bogus.
http://en.wikipedia.org/wiki/Bananadine

Reply With Quote
  #4  
Old   
Peter Nilsson
 
Posts: n/a

Default Re: REGEXP_REPLACE doesn't comply with the standard, does it ? - 06-30-2010 , 01:16 AM



On Jun 30, 6:44*am, joel garry <joel-ga... (AT) home (DOT) com> wrote:
Quote:
On Jun 29, 5:06*am, Spendius <spend... (AT) muchomail (DOT) com> wrote:
The following works *everywhere* I've ran it:
$ echo rbcde_fghijkl_mnopq|sed "s/_\([a-z]\)/\u\1/g"
rbcdeFghijklMnopq
snip
I've found no way to have the same behaviour using
REGEXP_REPLACE:
SQL> select regexp_replace('rbcde_fghijkl_mnopq','_\([a-z]
\)','\u\1')
from dual;
REGEXP_REPLACE('RBC
-------------------
rbcde_fghijkl_mnopq

How can you then obtain in SQL what I'm getting above in Ux ?

Well, initcap seems to work with underscores, then you get rid
of the underscores?

* 1 *select
replace(replace(initcap
('dummy'||'rbcde_fghijkl_mnopq'),'_',''),'Dummy',' ')
* 2* from dual
JEG@TTST> /

REPLACE(REPLACE(I
-----------------
rbcdeFghijklMnopq
Slightly simpler...

select str,
substr(replace(initcap('x' || str), '_', ''), 2)
from (
select 'rbcde_fghijkl_mnopq' str from dual union all
select '_xx_xx' str from dual
);

--
Peter

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.