I'm trying to build a regex that matches an expression that :
- start with a string (in my example :
<div
) - ends with another string (in my example :
</div>
) - contains a searched string (in my example :
searched string
).
Around this searched string can be anything included spaces and newlines.
Parsing : <div class="testclass">random example text</div>
<div id="testid">foo bar foo searched string foo bar</div>
Should match :
<div id="testid">foo bar foo searched string foo bar</div>
The first <div>
should not match, as it doesn't contain searched string
I've tried something like :
^(<div)(.|\s)*?(searched string)(.|\s)*?(</div>)$
But obviously it returns the whole tested expression as the (.|\s)*?
part matches everything until it finds the searched string.
I want the RegEx to reject the <div class="testclass">random example text</div>
part, as it does not contain searched string
Thanks for your help.
EDIT: I'm using sublime text 3 to perform this search, and for what I understand, it uses a custom proprietary regex engine, but I guess the logic could be similar to other languages like php.