I have a string comprised of my name christiancattano
and a regex search pattern defined as such
/(cattano|cattan|attano|chris|catta|attan|ttano|chri|hris|catt|atta|ttan|tano|chr|hri|ris|cat|att|tta|tan|ano)+/ig
In regex101 if I enter my search pattern in the top bar, and enter verbatim, christiancattano
into the test string box it will hightlight chris
and cattano
. This is the behaviour I am expecting.
In my javascript code if I run the following lines
var regExPattern: string = '(cattano|cattan|attano|chris|catta|attan|ttano|chri|hris|catt|atta|ttan|tano|chr|hri|ris|cat|att|tta|tan|ano)+';
var regExObj: RegExp = new RegExp(regExPattern, 'g');
var match: string[] = regExObj.exec('christiancattano');
console.log(`match: ${match}`);
I receive this output
match: chris,chris
Why is it that regex101 shows my matches being what I expect, chris
and cattano
, but my Javascript code is producing a different result?