How can I use a regular expression to match text that is between two strings, where those two strings are themselves enclosed two other strings, with any amount of text between the inner and outer enclosing strings?
For example, I have this text:
outer-start some text inner-start text-that-i-want inner-end some more text outer-end
In this case, I want text-that-i-want because it is between inner-start and inner-end, which themselves are between outer-start and outer-end.
If I have
some text inner-start text-that-i-want inner-end some more text outer-end
then I don't want text-that-i-want, because although it is between inner-start and inner-end, there is no outer-start enclosing these strings.
Likewise, if I have
outer-start some text text-that-i-want inner-end some more text outer-end
then again, I don't want text-that-i-want, because there is no enclosing inner-start, although there are enclosing outer-start and outer-end strings.
Assume that outer-start, inner-start, inner-end and outer-end will only ever be used for the purposes of enclosing/delimiting.
I reckon that I can do this by doing a two pass regular expression match, i.e. looking for any data between outer-start and outer-end, and then within that data looking for any text between inner-start and inner-end (if indeed those strings exist), but I would like to know if it can be done in one go.