There's no need to match past the CN=, then prepend the CN= back to the
string. Use the following
$dnvalue = "CN=foo,OU=bar,O=pah";
$dnvalue =~ /(CN=[A-Za-z0-9]*)/;
$username = $1;
print $username
This looks for CN= followed by any number of letters (upper or lowercase)
and numbers. If you don't mind matching on an underscore too (_) use the
following instead
$dnvalue =~ /(CN=\w*)/;
HTH
John
-----Original Message-----
From: Mike Ring [mailto:[EMAIL PROTECTED]]
Sent: 28 June 2001 17:17
To: [EMAIL PROTECTED]
Subject: simple regex question
Hello all.
I've learned a bit about regular expressions today. I have a string
formatted
like "CN=foo,OU=bar,O=pah" and I need to parse out "foo". I have created the
following code which does work:
$dnvalue =~ m/([^,]*)/;
$username = $1;
$username =~ s/(CN=)//;
print $username
However, I'd like to do the match/replace on a single line. Can anyone show
me
how to combine these statements into a more elegant regular expression?
Thanks,
Mike
--------------------------Confidentiality--------------------------.
This E-mail is confidential. It should not be read, copied, disclosed or
used by any person other than the intended recipient. Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful. If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.