Reputation: 63
I am trying to parse file paths to just get the file name and I have a regex .*\
I'll use the following
Select-String -Pattern '.*\\' -InputObject $test -NotMatch
on a file path like C:\Users\User\Desktop\test.exe and it returns blank. If I remove the -NotMatch flag it returns the entire path. I tried using a regex tester so I know the regex is correct. What am I doing wrong?
Upvotes: 0
Views: 601
Reputation: 27606
Looks like -notmatch just ignores the whole line if there's a match. How about this? This is any number of characters that are not backslashes at the end of a line.
'C:\Users\User\Desktop\test.exe' | select-string [^\\]*$ | % matches | % value
test.exe
Upvotes: 0