JSFiddle - React, Tailwind, and code Playground
by arcm111
JavaScript
var str= 'Now i am selected a text and using window.getselction() i can get the selected text but i want the previous 4 words before the selected text+SelectedText+4 words after the selected text so please tell me any way to get this thing at runtime,give me any standard way because i am working with multiple pages so can \'t fix particular ids'
var word = "please"
var regex = new RegExp('^.*?((\\S*\\s){1,4})(\\b' + word + '\\b)((\\s\\S*){1,4}).*?$');
var part = str.replace(regex, '$1 << $3 >> $4');
alert(part);