-
-
Save p0w3rsh3ll/19d46f50f5c5a621e8a59107fe0cc484 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# source: https://blogs.msdn.microsoft.com/powershell/2006/04/25/using-culture-culture-culture-script-scriptblock/ | |
Function Using-Culture { | |
Param( | |
[System.Globalization.CultureInfo]$Culture, | |
[ScriptBlock]$ScriptBlock | |
) | |
$OldCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture | |
trap { | |
[System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture | |
} | |
[System.Threading.Thread]::CurrentThread.CurrentCulture = $Culture | |
Invoke-Command -ScriptBlock $Scriptblock | |
[System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture | |
} | |
# https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-options#comparison-using-the-invariant-culture | |
# 1. Test a case insensitive regular expression match in the en-US culture | |
Using-Culture -Culture 'en-US' -ScriptBlock { | |
[regex]::IsMatch('file','FILE',[System.Text.RegularExpressions.RegexOptions]::IgnoreCase) | |
} | |
# 2. Test a case insensitive regular expression match in the tr-TR culture | |
Using-Culture -Culture 'tr-TR' -ScriptBlock { | |
[regex]::IsMatch('file','FILE',[System.Text.RegularExpressions.RegexOptions]::IgnoreCase) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment