hshobby, if I understand, your question is about the multiple-line replacement at the bottom. Is this what you are looking for? (If the title also need to be captured, that is an easy tweak.)
Search:
(?is)<div class="class1">[\s\r\n]*<div class="class2"></div>[\s\r\n]*<div class="title">([^<]+)</div>[\s\r\n]*</div>
Replace:
<div class="title">$1</div>
If so, here are some differences with your original expression. First off we are allowing the dot to match new line characters so that the regex can span several lines. This is what (?s)
does. Since you were turning on case-insensitive mode later on (?i)
, it seemed cleaner to bring it together at the front: (?is)
One repeated piece here is the [\s\r\n]*
character class, which eats up any spaces and new lines, allowing us to reach the next part of the string you are trying to match.
Finally, the title itself is matched and captured with [^<]+
which says one or more character that is not a <
, allowing us to consume all the characters before </div>
If a title can be empty, replace [^<]+
with [^<]*
Input:
<div class="class1">
<div class="class2"></div>
<div class="title">Hi there hsHobby</div>
</div>
Output:
<div class="title">Hi there hsHobby</div>