Solved

REGEXP_REPLACE Oracle

Posted on 2011-03-11
6
1,144 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
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 explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Via a live example, show how to take different types of Oracle backups using RMAN.

726 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