skahlert2010
asked on
REGEXP_REPLACE Oracle
Dear experts!
I need to extract "lwf-gr-gg-abt1" from the following string in sql:
CN=lwf-gr-gg-abt1,OU=abt_n eu,OU=grup pen,OU=LWF ,DC=my,DC= local,DC=d omain
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
I need to extract "lwf-gr-gg-abt1" from the following string in sql:
CN=lwf-gr-gg-abt1,OU=abt_n
I want to use a regular expression such and tried the following without success:
select user_name, regexp_replace(group_name,
Do you have a regualr expression that will work for me?
Many thanks for your help and thoughts,
skahlert2010
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ingenius!
Thanks sdstuber! It's working perfectly!
How did you figure out the correct syntax?
Regards,
Skahlert2010
Thanks sdstuber! It's working perfectly!
How did you figure out the correct syntax?
Regards,
Skahlert2010
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
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
ASKER
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!
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!
regexp_substr(group_name, 'CN=([^,]+)',1,1,null,1)