Skip to content

Instantly share code, notes, and snippets.

@peppekerstens
Created December 2, 2022 09:45
Show Gist options
  • Save peppekerstens/f0421ea484a512b75c5c4e0016a9edd1 to your computer and use it in GitHub Desktop.
Save peppekerstens/f0421ea484a512b75c5c4e0016a9edd1 to your computer and use it in GitHub Desktop.
Powershell smartmatch - simple replace subset spec char for -like and -match functions
function smartmatch{
param(
[string]$inputstring
)
if ($inputstring -match '\[') {
$inputstring = $inputstring.replace("[","\[")
}
if ($inputstring -match '\]'){
$inputstring = $inputstring.replace("]","\]")
}
if ($inputstring -match '\}'){
$inputstring = $inputstring.replace("}","\}")
}
if ($inputstring -match '\{'){
$inputstring = $inputstring.replace("{","\{")
}
if ($inputstring -match '\('){
$inputstring = $inputstring.replace("(","\(")
}
if ($inputstring -match '\)'){
$inputstring = $inputstring.replace(")","\)")
}
if ($inputstring -match '\+'){
$inputstring = $inputstring.replace("{","\{")
}
if ($inputstring -match '\|'){
$inputstring = $inputstring.replace("{","\{")
}
$inputstring
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment