Assume that we have:
- ABC_ANY_STRING_DEF
- ANY_STRING
- ANY_STRING_DEF
- ABC_CDE_ANY_STRING_DEF
"ABC_" or "CDE_" can be prefix or absent. In addition, "_DEF" can be postfix or absent.
In this case, can I extract ANY_STRING (which is just any set of characters, just a string) between prefix and postfix by using one regular expression?
For example, input = "ABC_CDE_I like an apple_DEF", then output must be "I like an apple".
I tried the following code, but it does not output what I expected.
re.compile("(?:ABC_|CDE_)*(\S+)(?:_DEF)?")
or
re.compile("(?:ABC_|CDE_)*(\S+)(?:_DEF)*")
Thanks a lot in advance for your advice.