在针对 Active Directory 执行某些任务时,我需要遵守一个术语。
这是命名法:
- TT-EEE-助记符:如果 TT = 'GA' 或 'GS' 或 'PA' 或 'PF' ->要创建的架构是一个“组”,groupScope 为全局。
- LT-EEE-助记符:如果T = 'A' 或 'G' 或 'I' 或 'N' 或 'P' ->要创建的架构是一个“组”,groupScope 为本地域。
- TTT-EEE-助记符:如果 TTT* = 'CNX' 或 'GST' 或 'SVC' ->要创建的 shema 是一个“用户”
- T-SSSS-助记符:如果T = 'A' 或 'L' 或 'M' 或 'R' 或 'S' ->要创建的架构是“organizationUnit”
我所追求的是一种比这更简单、更有效的方法:
If(dn.Substring(3, 2).Contains("GA") _
Or variable.Substring(3, 2).Contains("GS") _
Or dn.Substring(3, 2).Contains("PA") _
Or dn.Substring(3, 2).Contains("PF")) Then
schema = "group" ' Global'
Else If(dn.Substring(4, 1).Contains("A") _
Or dn.Substring(4, 1).Contains("G") _
Or dn.Substring(4, 1).Contains("I") _
Or dn.Substring(4, 1).Contains("N") _
Or dn.Substring(4, 1).Contains("P")) Then
schema = "group" ' Local'
Else If(dn.Substring(3, 3).Contains("CNX") _
' Well... You get the idea, don't you?
End If
我想我可以使用一个正则表达式,或者可能为我得到的每个命名法使用一个,类似的东西。
在这种情况下,有没有办法让 RegularExpression
变得方便?或者最好还是坚持那个古老的大假设?欢迎任何建议。
抱歉询问,但我不习惯使用 RegularExpression
。我知道它们的存在,也知道它们能做的一些事情,但仅此而已。
谢谢!
I have a nomenclature to respect while performing some tasks against the Active Directory.
Here's the nomenclature:
- TT-EEE-Mnemonic: if TT = 'GA' or 'GS' or 'PA' or 'PF' -> the schema to create is a "group", with a groupScope of Global.
- LT-EEE-Mnemonic: if T = 'A' or 'G' or 'I' or 'N' or 'P' -> the schema to create is a "group", with a groupScope of Domain local.
- TTT-EEE-Mnemonic: if TTT* = 'CNX' or 'GST' or 'SVC' -> the shema to create is an "user"
- T-SSSS-Mnemonic: if T = 'A' or 'L' or 'M' or 'R' or 'S' -> the schema to create is an "organizationUnit"
What I'm after is a simpler and more effective way than this:
If(dn.Substring(3, 2).Contains("GA") _
Or variable.Substring(3, 2).Contains("GS") _
Or dn.Substring(3, 2).Contains("PA") _
Or dn.Substring(3, 2).Contains("PF")) Then
schema = "group" ' Global'
Else If(dn.Substring(4, 1).Contains("A") _
Or dn.Substring(4, 1).Contains("G") _
Or dn.Substring(4, 1).Contains("I") _
Or dn.Substring(4, 1).Contains("N") _
Or dn.Substring(4, 1).Contains("P")) Then
schema = "group" ' Local'
Else If(dn.Substring(3, 3).Contains("CNX") _
' Well... You get the idea, don't you?
End If
I guess I could use a RegularExpression
, or perhaps one for each of the nomenclature I got, something alike.
Is there a way a RegularExpression
could become handy in this situation? Or would it be best to stick with that old big-If? Any suggestions are welcome.
Sorry for asking, but I'm not used to use RegularExpression
. I know they exist, and bit of what they can do, but that's all.
Thanks!
发布评论
评论(3)
您的代码似乎与您的描述不符。根据您的描述,您可能需要以下正则表达式:
编辑:您可能需要阅读 本教程 关于正则表达式的含义,请特别查找“字符类”和“分组和替代项”部分。
简而言之,横线字符(即|)是“OR”运算符。方括号(即[])是字符类;换句话说,字符之间是“OR”。
Your code does not seem to conform your description. With your description, you may want the following regular expression:
EDIT: you may want to read up this tutorial about what the regular expression means, specifically look for the "Character classes" and "Grouping and alternatives" sections.
In short, the bar character (i.e. |) is the "OR" operator. The square brackets (i.e. []) are the character class; in other words, "OR" between the characters.
它会大大减少测试和显式 Or 的数量。
It'd vastly reduce the number of tests and explicit
Or
s.怎么样...
How about...