Search This Blog

Nov 22, 2023

Demo - Regex

  •  any string as is but a particular string: ^(?!particularString$).*
  • Grouped match (it will return named group, give a host FQDN, below will return domainName   ^.*?\.(?<domainName>.*)
  • Matches duplicate line ^((?-s).+?)\R(?=(?s).*?^\1(?:\R|\z))
  • AD domain NETBIOS name when standalone
    [a-zA-Z0-9](?!.*[,:~!@#\$%\^'\.\(\)\{\}_ \/\\]).{0,14}\\
  • SAMaccountName
    ^(?!.*[\"\/\\\[\]:;|=,\+\*\?<>]).{1,19}$
  • AD domain NETBIOS name when followed by \userName (this also groups domain/user)
    ([a-zA-Z0-9](?![^\\]*[,:~!@#\$%\^'\.\(\)\{\}_ \/]).{0,14})\\((?!.*[\"\/\\\[\]:;|=,\+\*\?<>]).{1,19})
  • same for powershell match
    -match '^    ([a-zA-Z0-9](?![^\\]*[,:~!@#\$%\^''\.\(\)\{\}_ \/]).{0,14})\\((?!.*[\"\/\\\[\]:;|=,\+\*\?<>]).{1,19})'
  • DN --> OU path (stripping CN name)
    -match '^((.+?),)(OU=.*|CN=.*)' $OUPath = $matches[3]