这个怎么样:
# Create array of filenames
$files =
"[abs] anima.some e147 name [480p].avi",
"anima.some e147 name #anim group .avi",
"anima.some e147 name [480p].avi",
"anima some e147 name [480p].avi"
# Setup patterns to match against
$pattern1 = "\[\w+\] ([^.]+).([\w]+) ([\S]+) [\w]+ \[[\w]+\].avi"
$pattern2 = "([^.\s]+).([\w]+) ([\S]+) .*.avi"
# Loop through file names and attempt matching
foreach($f in $files)
{
if($f -match $pattern1)
{
$string = (Get-Culture).TextInfo.ToTitleCase($matches[1]) + " " + $matches[2] + " " + $matches[3] + ".avi"
$string
}
elseif($f -match $pattern2)
{
$string = (Get-Culture).TextInfo.ToTitleCase($matches[1]) + " " + $matches[2] + " " + $matches[3] + ".avi"
$string
}
else
{
"unmatched file: " + $f
}
}
输出是:
Anima some e147.avi
Anima some e147.avi
Anima some e147.avi
Anima some e147.avi