Re: Parse x.500 DN and change order displayed



Hallvard B Furuseth wrote:
SecureIT writes:
I am trying to change this
"cn=Bob Smith+serialNumber=CR013120080827,o=ICM,c=US"
to this:
"serialNumber=CR013120080827+cn=Bob Smith,o=ICM,c=US"

Without escape sequences like "\," and "\+" in the DNs (if that's
allowed anyway, I don't remember the details of X.500 Dn syntax), this
moves serialNumber first in each RDN:

s/(^|,)([^,]*)\+(serialNumber=[^+,]*)(?=[+,])/$1$3+$2/gi;
die "didn't catch all 'foo+serialNumber's" if /\+serialNumber=/i;

Using this regex will take care of \, and \+ escapes:

s/(^|(?<!\\),)((?:[^,]|\\,)*)\+(serialNumber=(?:[^+,]|\\[+,])*)(?=(?<!\\)[+,])/$1$3+$2/gi;


Matches:

my $dn = "cn=Bob Smith+serialNumber=CR013120080827,o=ICM,c=US";
$dn =~ s/
(^|(?<!\\),) ((?:[^,]|\\,)*) \+
(serialNumber = (?:[^+,] | \\[+,])*)
(?=(?<!\\)[+,])
/$1$3+$2/gix;
print $dn;


__OUTPUT__
serialNumber=CR013120080827+cn=Bob Smith,o=ICM,c=US


And:

my $dn = "cn=Smith\\, Bob+serialNumber=CR01312\\+0080827,o=ICM,c=US";
$dn =~ s/
(^|(?<!\\),) ((?:[^,]|\\,)*) \+
(serialNumber = (?:[^+,] | \\[+,])*)
(?=(?<!\\)[+,])
/$1$3+$2/gix;
print $dn;


__OUTPUT__
serialNumber=CR01312\+0080827+cn=Smith\, Bob,o=ICM,c=US


Hope this helps.

--
szr


.



Relevant Pages

  • Re: Parse x.500 DN and change order displayed
    ... this moves serialNumber first in each RDN: ... Using this regex will take care of \, ... nontrivial parsing like escape sequences, you have to be careful to ...
    (comp.lang.perl.misc)
  • Re: Parse x.500 DN and change order displayed
    ... moves serialNumber first in each RDN: ... Using this regex will take care of \, ... nontrivial parsing like escape sequences, you have to be careful to ...
    (comp.lang.perl.misc)
  • Re: Parse x.500 DN and change order displayed
    ... SecureIT writes: ... allowed anyway, I don't remember the details of X.500 Dn syntax), this ... moves serialNumber first in each RDN: ...
    (comp.lang.perl.misc)
  • Re: Regexp slowdown
    ... with the same weak logic that you use for the regex stuff. ... cr> What of that makes you think I'm worried about the syntax of my regex? ... cr> memory-intensive attempt at interpreter optimization by the perl folks. ... cr> had a mile-long stack frame I would see a performance hit. ...
    (comp.lang.perl.misc)
  • Re: Bash Regex II
    ... -bash: syntax error in conditional expression: unexpected token `(' ... Ich stehe gerade vor dem Problem einen Bash Regex für beide Versionen ... Obige Regex benötigt allerdings keine Zwischenvariable, ... (mit dem angedeuteten Problem beim Punkt). ...
    (de.comp.os.unix.shell)