I'm having trouble getting my regex to match all groups.
My regex: /^#(\\|?[^|]+\\|[^|]+\\|?)+?$/g
Test string: #something|somethingelse|morestuff|evenmorestuff
The matches I want are the things matches in pairs, as in: something|somethingelse
and morestuff|evenmorestuff
should be groups 1 and 2. But I can only get the last group to return.
My code looks like this (I'm using Javascript).
re = new RegExp('^#(\\|?[^|]+\\|[^|]+\\|?)+?$', 'g');
var matches = re.exec(window.location.hash);
console.log([matches[0], matches[1], matches[2]]);
matches[0]
returns the whole string
matches[1]
returns morestuff|evenmorestuff
matches[2]
is undefined.