/([a-zA-Z0-9\-])(@)([a-zA-Z0-9\-])/
In the regex above group 1 and group 3 contain same expression. Is there another way to use the same expression in another group beside typing it all over again?
/([a-zA-Z0-9\-])(@)([a-zA-Z0-9\-])/
In the regex above group 1 and group 3 contain same expression. Is there another way to use the same expression in another group beside typing it all over again?
If you are using PCRE, then you can do this:
/([a-zA-Z0-9\-])@(?1)/
^
() not needed around the @ sign
If you want to re-use a group, you could use recursion:
/([a-zA-Z0-9\-])(@)(?1)/
(?1)
will use the pattern from group 1. Let's now polish your regex:
/([a-zA-Z0-9\-])@(?1)/
/([a-zA-Z0-9-])@(?1)/
i
modifier: /([a-z0-9-])@(?1)/i
Further reading: