Regex: Matching against groups in different order without repeating the group
Posted
by Jimmy
on Stack Overflow
See other posts from Stack Overflow
or by Jimmy
Published on 2010-04-08T00:48:46Z
Indexed on
2010/04/08
0:53 UTC
Read the original article
Hit count: 346
regex
|alternative
Let's say I have two strings like this:
XABY
XBAY
A simple regex that matches both would go like this:
X(AB|BA)Y
However, I have a case where A and B are complicated strings, and I'm looking for a way to avoid having to specify each of them twice (on each side of the |). Is there a way to do this (that presumably is simpler than having to specify them twice)?
Thanks
© Stack Overflow or respective owner