given these strings:
a
b
ab
ba
bab
aba
abab
babab
asdgasdgsdgasa
I want the following output: true true false false true true false true true
I have this regex ^([ab])(?:.*?\1)?$
It matches well in this debugger: https://regex101.com/ However it doesn't match anything in this debugger: https://regexr.com/
Why is that?
Also why this gives true:
console.log(/^([ab])(?:.*?\1)?$/.test('aba'))
true
While the following gives false?
var re = new RegExp("^([ab])(?:.*?\1)?$");
re.test("aba");
false
My question is not to provide new ways or new regexps that match those strings. I just want to:
1) understand why there are such differences between regex debuggers
2) If the regex I gave is good to match such strings
3) Why the first console log matches, while the second does not and what should I change in order to make it work with re.test