PowerShell: Recursive Regular Expression This topic contains 2 replies, has 2 voices, and was last updated by alta4096 3 weeks, 6 days ago. Author Posts June 21, 2018 at 8:07 am #102892 alta4096Participant Hello All, I would like to know if it is possible to use Recursive Regular Expression Or if there is a regular expression that check for LDAP filter syntax. To be more specific I am looking for a LDAP filter syntax regex in order to add it as a ValidatePattern Validation Attribute like this: Param ( [parameter(Mandatory=$true)] [ValidatePattern("(\s*\((?:[&|]\s*RECURSIVE+|(?:!\s*RECURSIVE)|[a-zA-Z][a-zA-Z0-9-]*[~]?=[^()]*)\s*\)\s*)")] [String] $LDAPFIlter ) LDAP Syntax Filter https://tools.ietf.org/search/rfc2254 I found this in perl: /^(\s*\((?:[&|]\s*(?1)+|(?:!\s*(?1))|[a-zA-Z][a-zA-Z0-9-]*[~]?=[^()]*)\s*\)\s*)$/ ref: https://rgxdb.com/r/5VS2C5LM But it is using recursive pattern (?1)+ . I think it is to get the correct amount of parenthesis. I see that python as an addition to it that will allow the "recursive " parts. https://pypi.org/project/regex/ Thank you in advance for your time. Ref: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_regular_expressions?view=powershell-6 https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-6#validatepattern-validation-attribute June 21, 2018 at 1:58 pm #102913 jsParticipant Just wondering, why not sure a regular -filter, which is either powershell or sql syntax? June 22, 2018 at 8:23 am #103003 alta4096Participant Hi js, Yes thanks, I suppose that even if System.DirectoryServices.DirectorySearcher is used , the LDAP filter needs a specific format like "(&(objectCategory=User)(Department=IT))" or "(&(sAMAccountName< =a)(!(sAMAccountName=$*)))" ref for AD : https://social.technet.microsoft.com/wiki/contents/articles/5392.active-directory-ldap-syntax-filters.aspx The validation would be to confirm if the filter format is correct or not. For SQL syntax , this is not possible unfortunately. This is not an AD. Just LDAP. Author Posts You must be logged in to reply to this topic.