As explained in https://mathematica.stackexchange.com/a/72293/45020, using
StringCases does not actually return the shortest matching string. Instead it looks until some part matches (from left to right) and then it looks ahead and stops at the first complete match from that position. Of course this misses the true shortest string whenever this first match is not part of the shortest string. See for example
StringCases["This is not what I'm looking for. This is part of the shortest match", Shortest["This is" ~~ any__ ~~ "match"]]
where the whole string gets matched while a stronger string match is available.
I need the reverse behavior. Where one searches from right to left (Alternatively I need to find the "true" Shortest substring, that would also work for my application).
I have a
StringExpression that describes some pattern, say "out ["~~x: NumberString~~"]", which at some point is preceded by some strong "some_string" from which I want to extract the string between the end of the regular pattern and the closest preceding instance of "some_string". So for example
reverseShortestCase["some_string other stuff I don't want. some_string, the part I do want, out [3.1]", "some_string", "out ["~~x: NumberString~~"]"]
"some_string, the part I do want, out [3.1]".
How should I go about doing this? I guess I can try to reverse the string and the patterns in order to search right to left? But this seems complicated if you want to be able to use things like NumberString.
The solutions proposed in the linked question do not seem to offer a solution for this case where there is no fixed begin and end string and instead a StringExpression needs to be used to describe these.