[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

REGEXP_REPLACE Oracle

Posted on 2011-03-11
6
Medium Priority
?
1,164 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
  • 3
  • 2
6 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 1600 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 400 total points
ID: 35108250
0
Industry Leaders: 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
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 video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example, show how to take different types of Oracle backups using RMAN.
Suggested Courses
Course of the Month20 days, 12 hours left to enroll

865 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