SyntaxFix
Write A Post
Hire A Developer
Questions
If you're working with actual files (as opposed to some sort of string data), how about the following?
$files | % { "$($_.BaseName -replace '_[^_]+$','')$($_.Extension)" }
(or use _.+$ if you want to cut everything from the first underscore.)
_.+$