I\'m struggling to work with regular expressions. I think I understand the individual expressions but combining something together has me completely stumped. I don\'t grasp th
You've almost got it. It's really as simple as replacing 'or' with |
and replacing and
with concatenation. Then make sure your groups are unmatching by adding ?:
to the beginning of each:
(?:<|<\/)(?:[1-9]|[1-4][0-9]|[5][0-7])>
MDN has an explanation on the interaction of split and regex. But the short example-explanation is:
'hi_joe'.split('_'); // ['hi', 'joe']
'hi_joe'.split(/_/); // ['hi', 'joe']
'hi_joe'.split(/(_)/); // ['hi', '_', 'joe']
'hi_joe'.split(/(?:_)/); // ['hi', 'joe']
Update per comment, if you'd like the <##> in your results array as well, wrap the regex in an additional set of parens.
((?:<|<\/)(?:[1-9]|[1-4][0-9]|[5][0-7])>)