2021-07-14

PowerShell Invoke-WebRequest Emoji and Special Character Escape for FileName

這會把一些中文全形標點符號也過濾掉

$Name = '[😀😃😄😁😆]';

$EmojiRegex = New-Object System.Text.RegularExpressions.Regex('(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])')

$Name = ($Name -Replace '\|','');
$Name = ($Name -Replace '\?','');
$Name = ($Name -Replace '\*','');
$Name = ($Name -Replace '\/','');
$Name = ($Name -Replace '\\','');
$Name = ($Name -Replace '<','');
$Name = ($Name -Replace '>','');
$Name = ($Name -Replace '"','');
$Name = ($Name -Replace ':','');
$Name = ($Name -Replace '\[','');
$Name = ($Name -Replace ']','');
$Name = ($Name -Replace '\.','');
$Name = ($Name -Replace '&amp;','&');
$Name = ($Name -Replace '&quot;','');
$Name = ($Name -creplace $EmojiRegex);

$Name;

沒有留言:

張貼留言