Eu não sou um especialista em regex, desculpe; no entanto, posso oferecer minha tentativa rudimentar:
$name = dir *.mp4 | select BaseName ### no such files; see next herestrig workaround:
$name = @'
[year]TEST2[TEST3]-TEST4
[1979] Name of the movie [P1] - Disney
[1979] Name of the movie [P1] [Director's Cut] - PTC
[1980] Name of the movie [P8][Director Edition] - Test Studios
'@ -split [System.Environment]::NewLine
$regex = [regex]"\[(\w+)\](\w+\[\w+\])-(\w+)" # wrong: original
$regex = [regex]"\[(\w+)\]([\s*\w]+[\s*\[\w+\]]+)\s*-\s*(\w+)" # wrong: Apostrophe
$regex = [regex]"\[(\w+)\]\s*(\w+[\s*\[\w+'*\]]+?)\s*\-\s*([\s*\w+]+)" # works
$regex = [regex]"\[(\w+)\]\s*(\w+[\s*\[\w+'*\]]+?)\s*\-\s*(.*$)" # works
foreach ($n in $name)
{
$file_name = $n #.BaseName.ToString();
$year, $title, $studio = $regex.Match($file_name).groups[1,2,3] |
Select -ExpandProperty Value
"$year,$title,$studio," ### debugging output
}
Saída :
PS D:\PShell> D:\PShell\SU98893.ps1
year,TEST2[TEST3],TEST4,
1979,Name of the movie [P1],Disney,
1979,Name of the movie [P1] [Director's Cut],PTC,
1980,Name of the movie [P8][Director Edition],Test Studios,