I have been trying to get to write a regex that ignores all text post the fifth occurrence of backslash, e.g below text; language in question is powershell
\\Fileserver\Usershare$\Svr2008\Profiles\john.contoso.V2
I made multiple attempts but no avail, the best i could do was match everything post usershare$, using ([^\$]*$)
which gives me \\Fileserver\Usershare$
I would like the output to be \\Fileserver\Usershare$\svr2008
Any help would be appreciated.
As suggested by Mik i tried ^\\\\([^\\]*\\){3}
and used it as
$Parent= \\Fileserver\Usershare$\Svr2008\Profiles\john.contoso.V2
$test = $parent -replace '^\\\\([^\\]*\\){3}'
$test
I get the below
Svr2008\Profiles\john.contoso.V2
However i require the part that didn't match, am i doing something wrong?