I have a very simple code:
var allTypes = "restaurant|dentist";
var typeSplitter = new RegExp("([a-zA-Z]+)");
typeSplitter.exec(allTypes);
I want an array like this:
[“restaurant”, “dentist”]
But instead I get this:
[“restaurant”, “restaurant”]
I did test my regex here. I’ve been fiddling for way to long with this, probably something I don’t know about
Just do this
.splitcan also take a regex; even though it’s not necessary in this caseBut if you really want to use regex to capture, you have to use
.match