79626144

Date: 2025-05-17 03:35:00
Score: 1.5
Natty:
Report link

I like @sonjz answer (https://stackoverflow.com/a/24190283/4582204) the best, but it is case-SENSITIVE. To make it case-INsensitive, here are two options (edited repost of: https://stackoverflow.com/a/79626135/4582204).

mode modifier (?i) :

([regex]'(?i)a.b').Matches('A1B_A2B') | ft

Or use the class function, rather than instance/object function, and pass an option or flag.

$string = 'A1B_A2B'
$regex = 'a.b'
$flags = 'IgnoreCase'
[regex]::matches($string, $regex, $flags) | ft

or simply:

[regex]::match('A1B_A2B', 'a.b', 'IgnoreCase') | ft

Both approaches return 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  
Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @sonjz
  • Low reputation (0.5):
Posted by: john v kumpf