const regex1 = /(?\w+):(?\d+)/; const regex2 = /(?\w+):(?[a-z]+):(?\w+)/; const result = regex2.exec("foo:abc:bar"); expect(result.groups).toEqual({ alpha: "foo", bravo: "abc", charlie: "bar", });