I really like Regular Expressions. I was wondering if this kind of things can be done in JavaScript.
Imagine that you want to match the words foo and bar, but only when they are followed by "?" Or "!". I know that this simple case could be done with x(?=y)
, but my intention here is to know if you can place one RegEx inside another, as it would be great for more difficult scenarios.
I mean something like this:
var regex1 = /foo|bar/;
var regex2 = /{regex1}[\?\!]/;
This would simplify very complex regexes and would make some patters reusable without having to write the same patterns every time you need it. It would be something like a RegEx variable, if that makes sense.
Is it possible?