Imaging the following multi-line text:
foo1
some text
foo12
some text
bar
some text
foo123
some text
I want to find out to which foo belongs bar. In other words, I need to match only the numbers immediately after the last foo which still has bar after it.
In the example above the last foo meeting the condition is foo12, so I would like to match 12.
I have almost no clue about regex and so far I got something like:
(?s)(?<=foo)\d*(?=.*bar)
You can check it out here:
https://regex101.com/r/FiwO14/1
It is matching the numbers after the first two foo (foo1 and foo12), but I need just the second of them.