I think the most convenient answer (besides the mode modifier (?i)
above) which is case-insensitive and also will match multiple times on a single line (-Match
will not) (https://stackoverflow.com/a/24190283/4582204) is:
$string = 'A1B_A2B'
$regex = 'a.b'
$flags = 'IgnoreCase'
[regex]::matches($string, $regex, $flags) | ft
or simply:
[regex]::match('A1B_A2B', 'a.b', 'IgnoreCase') | ft
Which returns a 2-element array (really a MatchCollection
):
Groups Success Name Captures Index Length Value
------ ------- ---- -------- ----- ------ -----
{0} True 0 {0} 0 3 A1B
{0} True 0 {0} 4 3 A2B