Reverse the string and use a negative lookahead instead.
template.split("").reverse().join("")
.split(/\.(?!\\)/)
.split("").reverse().join("");
That's a "fun" way of doing it but for your case there are other ways that may be better. Like replacing all \.
with a magic string like __MAGIC__
, splitting by .
, then undoing the magic strings.