You should not be using regular expressions offered above. The problem with those regular expressions is that you will not follow RFC 4514 and will not unescape previously escaped symbols and may potentially loose or misinterpret a distinguished name.
Use LdapName class instead as recommended by musiKk to parse a distinguished name correctly.