I have the following string:
cn=abcd,cn=groups,dc=domain,dc=com
Can a regular expression be used here to extract the string after the first "cn=" and before the first ","? In the example above the answer would be "abcd".
Thanks.
I have the following string:
cn=abcd,cn=groups,dc=domain,dc=com
Can a regular expression be used here to extract the string after the first "cn=" and before the first ","? In the example above the answer would be "abcd".
Thanks.
Yeah, using perl/java syntax cn=([^,]*),
. You'd then get the 1st group.
/cn=([^,]+),/
most languages will extract the match as $1 or matches[1]
If you can't for some reason wield subscripts,
$x =~ s/^cn=//
$x =~ s/,.*$//
Thats a way to do it in 2 steps.
If you were parsing it out of a log with sed
sed -n -r '/cn=/s/^cn=([^,]+),.*$/\1/p' < logfile > dumpfile
will get you what you want. ( Extra commands added to only print matching lines )