Solved

REGEXP_REPLACE Oracle

Posted on 2011-03-11
6
1,135 Views
Last Modified: 2012-06-27
Dear experts!

I need to extract "lwf-gr-gg-abt1" from the following string in sql:

CN=lwf-gr-gg-abt1,OU=abt_neu,OU=gruppen,OU=LWF,DC=my,DC=local,DC=domain

I want to use a regular expression such and tried the following without success:

select user_name, regexp_replace(group_name, 'CN=(.*),CN=(.*)','\1') from table

Do you have a regualr expression that will work for me?

Many thanks for your help and thoughts,

skahlert2010
0
Comment
Question by:skahlert2010
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 400 total points
ID: 35108186
substr(regexp_substr(group_name, 'CN=[^,]+'),4)
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 35108219
if you're on 11g you can use subexpressions

regexp_substr(group_name, 'CN=([^,]+)',1,1,null,1)
0
 
LVL 7

Assisted Solution

by:Gene_Cyp
Gene_Cyp earned 100 total points
ID: 35108250
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:skahlert2010
ID: 35108268
Ingenius!

Thanks sdstuber! It's working perfectly!

How did you figure out the correct syntax?

Regards,

Skahlert2010
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 35108316
how?

it's all about patterns then figuring out what rule defines that pattern.


So, first, how do I identify the string you want.
I figured the pattern was everything between "CN="  and ","

so,  the expression was CN=  at the start, that part was easy.
continuing until the comma meant I had to take everything that wasn't a comma

[^,]  means not-comma

[^,]+ means 1 or more not-comma

then it's just a matter of pulling the "CN="  part off  and in 10g use substr to skip the first 3
in 11g, wrap it in parentheses and choose that subexpression
0
 

Author Comment

by:skahlert2010
ID: 35108373
Thanks for clarifying your attempt!

Makes it much easier to understand!

Thank you Gene_Cyp for pointing at the oracle resource! I have it already bookmarked!

Have a great weekend guys!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Via a live example, show how to take different types of Oracle backups using RMAN.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question