How to find a word enclosed from HTML tags?

I program spell checking in Javascript in conjunction with the OpenOffice dictionary, and I have a serious problem.

I can find whole words using RegEx, but if the word looks like prog<b>ram</b>ing, I can find it if I remove all the html tags using the method .text()from jQuery. But how can I replace this word and restore the original html structure?

Spellchecker.com does it very smartly - spellchecking even recognizes words of the type prog<b>ram</b>ingif they are spelled incorrectly!

+3
source share
2 answers
/([\s>"'])prog(<[^>]+>)ram(<[^>]+>)ing([\s\.,:;"'<])/g 

will match your example

, , , html

 var regExp = new RegExp('([\s>"\'])' + word.split('').join('(<[^>]+>)') + '([\s\.,:;"\'<])',g);

, . , , , " , html, html, - , , , :

String.prototype.stripHtml = function() {
  return this.replace(/(<[^>]+>)/, '');
}
+2

-, HTML, . - , javascript, , . -, "" html .text(), .

- : http://metacpan.org/pod/HTML::Scrubber

0

Source: https://habr.com/ru/post/1733858/


All Articles