Regex from stackoverflow

get 5 charactes before and after mark tag and select everything in between and add [...] before and after

by Subigya Panta

HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<p>Lorem ipsum <mark>dolor</mark> sit amet. <mark>Lorem</mark> ipsum again
   and <mark>dolor</mark></p>

JavaScript

var myText = $('p').html();
var reg = new RegExp("([\\w\\s.]{5})<mark>([^<]+)<\/mark>([\\w\\s]{5})", "gim");
var match = null, matches = [];
while ((match = reg.exec(myText)) !== null) {
	matches.push( '[...] ' + match[1] + ' ' + match[2] + ' ' + match[3] + '[...]');
}
console.log( matches );