public static void main(String[] args) { Document doc = Jsoup.parse("<p>Barcelona is a nice place to live !<br/>Other cities <b>too</b>!</p>"); dumpDocument("** BEFORE **", doc); Matcher replacer = Pattern.compile("(?i)(barcelona)").matcher(""); for (Element elt : doc.body().select("*")) { for (TextNode textNode : elt.textNodes()) { String originalText = textNode.text(); if (replacer.reset(originalText).find()) { String annotatedHtml = replacer.replaceAll("<span class=\"city\">$1</span>"); textNode.before(annotatedHtml); textNode.remove(); } } } dumpDocument("** AFTER **", doc); } private static void dumpDocument(String title, Document doc) { System.out.println(title); System.out.println(doc.html()); System.out.println(); }