Imagine I have a text file full of cat poems and need to find all poems that end with the word dog. The poems all start with the word cat. How do I match only poems that start with cat and end with dog?
Cat poem:
My feline is very furry
I like furry felines
This is why I do not have a dog
Cat poem:
Littly furry paws
this is what i like
I don't care if it's a feline or a canine
Cat poem:
The little felines
playing in the field
sitting on the side watching is a dog
In my example, I want the first and last poem to be matched while the middle should not be matched. If all poems ended with dog, (?=cat).*?(?<=dog)
would be an easy solution (thanks to this answer). However, this first matches the first poem and then the second and third poem together (as there is no dog in the second poem). Any extension to that regex I tried yielded just the same result, e.g. (?=cat).*?(?!cat).*?(?<=dog)
.
I am using Notepad++ (v6.5.2) so any answer should include a solution for that. If another environment allows a more elegant solution, feel free to add that, too.