Lookaheads and [lookbehinds](https://github.com/tc39/proposal-regexp-lookbehind) are probably worth considering.