Muh*_*riq 7 javascript regex ldap dn
我想要一个正则表达式来代表所有类型的DN
我创造了一个但不太好.
/([A-z0-9=]{1}[A-z0-9]{1})*[,??]/
和其他一些人通过改变它,但是徒劳无功.
可能的DN可以
CN=abcd,CN=abcd,O=abcd,C=us
CN=abcd0520,CN=users,O=abcd,C=us
C=us
etc
Run Code Online (Sandbox Code Playgroud)
Gle*_*ane 12
我最近需要这个,所以我创建了一个完全遵循RFC-2253的LDAPv3专有名称语法.
attributeType可以用2种方式表示.以alpha开头的字母数字字符串,使用以下方法验证:
[A-Za-z][\w-]*
或者它可以是OID,使用以下方式验证:
\d+(?:\.\d+)*
所以attributeType使用以下方式验证:
[A-Za-z][\w-]*|\d+(?:\.\d+)*
attributeValue可以用3种方式表示.十六进制字符串,是带有前导的十六进制对的序列#
.十六进制字符串验证使用:
#(?:[\dA-Fa-f]{2})+
或逃脱的字符串; 每个非特殊字符都表示为"原样"(使用验证[^,=\+<>#;\\"]
).特殊字符可以用前导表示\
(使用验证\\[,=\+<>#;\\"]
).最后,任何字符都可以表示为带有前导的十六进制对\
(验证使用\\[\dA-Fa-f]{2}
).转义字符串使用以下方式验证:
(?:[^,=\+<>#;\\"]|\\[,=\+<>#;\\"]|\\[\dA-Fa-f]{2})*
或者是带引号的字符串; 值开始和结束"
,并且可以包含任何未转义的字符,除了\
和"
.另外,可以使用来自上述转义字符串的任何方法.带引号的字符串使用以下方式验证:
"(?:[^\\"]|\\[,=\+<>#;\\"]|\\[\dA-Fa-f]{2})*"
所有组合,attributeValue使用以下方式验证:
#(?:[\dA-Fa-f]{2})+|(?:[^,=\+<>#;\\"]|\\[,=\+<>#;\\"]|\\[\dA-Fa-f]{2})*|"(?:[^\\"]|\\[,=\+<>#;\\"]|\\[\dA-Fa-f]{2})*"
BNF中的名称组件是:
name-component = attributeTypeAndValue *("+" attributeTypeAndValue)
attributeTypeAndValue = attributeType "=" attributeValue
Run Code Online (Sandbox Code Playgroud)
在RegEx中:
(?#attributeType)=(?#attributeValue)(?:\+(?#attributeType)=(?#attributeValue))*
用上面的值替换(?#attributeType)
和(?#attributeValue)
占位符给我们:
(?:[A-Za-z][\w-]*|\d+(?:\.\d+)*)=(?:#(?:[\dA-Fa-f]{2})+|(?:[^,=\+<>#;\\"]|\\[,=\+<>#;\\"]|\\[\dA-Fa-f]{2})*|"(?:[^\\"]|\\[,=\+<>#;\\"]|\\[\dA-Fa-f]{2})*")(?:\+(?:[A-Za-z][\w-]*|\d+(?:\.\d+)*)=(?:#(?:[\dA-Fa-f]{2})+|(?:[^,=\+<>#;\\"]|\\[,=\+<>#;\\"]|\\[\dA-Fa-f]{2})*|"(?:[^\\"]|\\[,=\+<>#;\\"]|\\[\dA-Fa-f]{2})*"))*
这验证了单个名称组件.
最后,BNF的杰出名称是:
name-component *("," name-component)
在RegEx中:
(?#name-component)(?:,(?#name-component))*
用上面的值替换(?#name-component)占位符可以得到:
^(?:[A-Za-z][\w-]*|\d+(?:\.\d+)*)=(?:#(?:[\dA-Fa-f]{2})+|(?:[^,=\+<>#;\\"]|\\[,=\+<>#;\\"]|\\[\dA-Fa-f]{2})*|"(?:[^\\"]|\\[,=\+<>#;\\"]|\\[\dA-Fa-f]{2})*")(?:\+(?:[A-Za-z][\w-]*|\d+(?:\.\d+)*)=(?:#(?:[\dA-Fa-f]{2})+|(?:[^,=\+<>#;\\"]|\\[,=\+<>#;\\"]|\\[\dA-Fa-f]{2})*|"(?:[^\\"]|\\[,=\+<>#;\\"]|\\[\dA-Fa-f]{2})*"))*(?:,(?:[A-Za-z][\w-]*|\d+(?:\.\d+)*)=(?:#(?:[\dA-Fa-f]{2})+|(?:[^,=\+<>#;\\"]|\\[,=\+<>#;\\"]|\\[\dA-Fa-f]{2})*|"(?:[^\\"]|\\[,=\+<>#;\\"]|\\[\dA-Fa-f]{2})*")(?:\+(?:[A-Za-z][\w-]*|\d+(?:\.\d+)*)=(?:#(?:[\dA-Fa-f]{2})+|(?:[^,=\+<>#;\\"]|\\[,=\+<>#;\\"]|\\[\dA-Fa-f]{2})*|"(?:[^\\"]|\\[,=\+<>#;\\"]|\\[\dA-Fa-f]{2})*"))*)*$
Muh*_*riq -1
我创建了一个。工作得很好。
^(\w+[=]{1}\w+)([,{1}]\w+[=]{1}\w+)*$
Run Code Online (Sandbox Code Playgroud)