I'm missing something with my use of regex, because my line works when I replace defined strings. I tried \d
and [0-9]
. What am I forgetting?
Original FOOBAR_12345678-0001.csv
Goal 12345678.csv
get-childitem *.csv | foreach { rename-item $_ $_.Name.Replace("FOOBAR_(\d{8})-\d{4}", "$1") }
The following works for me:
get-childitem *.csv | foreach { rename-item $_ ( $_.Name -replace 'FOOBAR_(\d{8})-\d{4}', '$1') }
Why: