Reputation: 1156
I have a string like this:
abcabcdeabc...STRING INSIDE...xyz
I want to find "...STRING INSIDE..." so I'm using the regex below to match it:
(?<=abc).*(?=xyz)
The issue is there are duplicated "abc" in the string so it returns "abcdeabc...STRING INSIDE..." but I only want to match anything between the last "abc" and "xyz". Is this possible? And if yes, how can I achieve this? Thank you.
Try it here: https://regex101.com/r/gS9Xso/3
Upvotes: 2
Views: 1662
Reputation: 520968
Try this pattern:
.*(?<=abc)(.*)(?=xyz)
The leading .*
will consume everything up until the last abc
, then the number will be captured.
We can also try using the following pattern:
.*abc(.*?)xyz
Here is a demo for the second pattern:
Upvotes: 2