Sublime text find/replace remove </div>

html, regex, sublimetext, sublimetext2, sublimetext3

Solution

You can do this using a regex. Select `Find -> Replace`, and make sure the `Regular Expression` button is selected. In `Find What:`, put

(?s)<div class="some-class">(.*?)<\/div>

and in `Replace With:`

$1

Example here

`(?s)` makes `.` match newline characters as well. The capture group `(.*?)` matches all characters in a non-greedy fashion, so that the group ends at the first `</div>`. Otherwise, it would match all the way up to the last `</div>` (example). The replace value `$1` is the first (and in this case only) matching group.

Problem

``` <div class="some-class"> Variable content here </div> ``` I want to leave the content in place however the surrounding div should be removed. Obviously the opening div part is easy to get rid of but that would leave hundreds of `</div>`s floating around then.

Original source