I am trying to match filenames using boost::regex and I have two kinds of patters:
XYZsomestringXYsomestringENDING
The string somestring can be anything (>0 characters).
The beginning of the filename is either XYZ or XY.
If it is XY , there has to be the string ENDING that terminates the whole sequence.
I tried to combine two regex with | but it doesnt work.
This matches filenames with the first pattern:
(XYZ)(.*)
and this matches filenames with the second pattern:
(XY)(.*)(ENDING)
But when I combine them, only the first pattern matches:
((XYZ)(.*))|((XY)(.*)(ENDING))
All this is supposed to be case insensitive, that is why I use boost::regex::icase in the constructor.
I have tried it without that icase, doesnt work either).
Any suggestions?
There may be simpler expressions but I think the regex
^xy(?(?!z).*ending$|.*$)should do it:Here's a live demo.
Edit: Additionally, I think the regex
^xy(z.*|.*ending)$should work as well.