My problem is I want to delete a <div> xxx </div>
from within an arbitrary page of HTML.
So given a page ...
<div> foo <div> bar <div> xxx </div> foo </div> bar </div>
I want to end up with
<div> foo <div> bar foo </div> bar </div>
I thought that replaceFirst("<div.*?xxx.*?</div>", "")
would do it. I assumed the magic ? would make the match lazy and leave the initial divs. However it insisted on being greedy and matching from the first div.
Since it took me an hour to find a solution, I'm posting my answer below to save those that follow.