Skip to content

Instantly share code, notes, and snippets.

@p0w3rsh3ll
Created September 5, 2018 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save p0w3rsh3ll/19d46f50f5c5a621e8a59107fe0cc484 to your computer and use it in GitHub Desktop.
Save p0w3rsh3ll/19d46f50f5c5a621e8a59107fe0cc484 to your computer and use it in GitHub Desktop.
# 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