How to test if a string contains one of multiple substrings?
You could use the -match method and create the regex automatically using string.join:
$referenz = @('abc', 'def', 'xyz') $referenzRegex = [string]::Join('|', $referenz) # create the regex
Usage:
"any string containing abc" -match $referenzRegex # true"any non matching string" -match $referenzRegex #false
Regex it: $a -match /\a|def|xyz|abc/g(https://regex101.com/r/xV6aS5/1)
- Match exact characters anywhere in the original string:'Ziggy stardust' -match 'iggy'