PowerShell: Recursive Regular Expression

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:


LDAP Syntax Filter

I found this in perl:


ref: LDAP query | Regex DB

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.

Thank you in advance for your time.



Just wondering, why not sure a regular -filter, which is either powershell or sql syntax?

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.