I have a pretty simple regex expression,
"lang-bash".match("lang-([a-z]+)", "gi")
And on latest Chrome (43-ish) I get the expected behaviour of ["lang-bash", "bash"]
. When I try to the same on the latest FireFox (39 or 41a) I get ["lang-bash"]
. I also tried this in Safari (8.0.7) and it has the expected result of ["lang-bash", "bash"]
.
So this might be a bug in FireFox, which I can submit for, but I'm expecting it's just something I don't understand. Thanks!
Edit: Alright... so some more testing.
FireFox
"lang-bash lang-dash".match(/lang-([a-z]+)/i)
Array [ "lang-bash", "bash" ]
"lang-bash lang-dash".match(/lang-([a-z]+)/ig)
Array [ "lang-bash", "lang-dash" ]
"lang-bash lang-dash".match("lang-([a-z]+)", "gi")
Array [ "lang-bash", "lang-dash" ]
Safari
"lang-bash lang-dash".match(/lang-([a-z]+)/i)
[ "lang-bash", "bash" ]
"lang-bash lang-dash".match(/lang-([a-z]+)/ig)
[ "lang-bash", "lang-dash" ]
"lang-bash lang-dash".match("lang-([a-z]+)", "gi")
["lang-bash", "bash"]
Chrome
"lang-bash".match(/lang\-([a-z]+)/i)
["lang-bash", "bash"]
"lang-bash".match(/lang\-([a-z]+)/gi)
["lang-bash"]
"lang-bash lang-dash".match("lang-([a-z]+)", "gi")
["lang-bash", "bash"]
Since there's a capture, I'd expect the result of anything with the flags ig
to be [ "lang-bash", "lang-dash", "bash", "dash" ]
but I guess that's not correct at all. It seems all the browsers act differently here. Anyone have some idea what's going on?