How to match the following cases with regex:
XYZABC
ABC
but not these:
XYZ*ABC
*ABC
in order to capture the ABC
part, which can be anything, including a (second) *
?
I've tried the following, but it does not work.
(?:XYZ)?(?!\*)(.+)
You may use this regex with a possessive quantifier which is supported in boost c++ regex engine:
^(?:XYZ)?+(?!\*)(.*)
PS: Used \n
inside negated character class for demo purpose only.
RegEx Details:
^
: Start(?:XYZ)?*
: Match xyz
optionally. Note that ?*
is possessive quantifier to disallow backtracking(?!\*)
: Make sure there is no *
at the immediate next position(.*)
: Match 0 or more of any characters and capture the value in group #1