Extract a substring with a regular expression in PowerShell
One way is:
$a = "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DNS Server\anyLongString]"
$a -match '([^\\]*)]$'
$matches[1]
anyLongString
Another way to do it is using fewer lines of code:
$a = "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DNS Server\anyLongString]"
$a -Replace '^.*\\([^\\]+)]$', '$1'