Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><del>replaceAll already works with StringBuffers anyway. (Well, to be precise, Matcher.replaceAll() uses StringBuffer, but String.replaceAll only delegates to Matcher.replaceAll() )</p> <p>For better performance you could build up the regex String by using a StringBuffer:</p> <pre><code> String head = "(?i)("; String tail = ")(?!([^&lt;]+)?&gt;&gt;)"; StringBuffer regex = new StringBuffer(); regex.append(head); regex.append(keyword); regex.append(tail); text.replaceAll(regex.toString(), "&lt;b&gt;$1&lt;/b&gt;"); </code></pre> <p>I don't really know, if there is a faster Replacement Implementation than the one of the Matcher class. But before you implement it yourself by using StringBuffer, I wanted to tell you, that it's already implemented that way.</del></p> <p>The following pseudocode might be buggy, but you could try it like this. (better performance is not guaranteed, but this should be the same as above without regex)</p> <pre><code>StringBuffer sb = new StringBuffer(text); int i = 0; int size = text.size() while(i&lt;size) { if(sb.charAt(i) == '&lt;') { increase i until you find '&gt;'; } if(sb.charAt(i) == keyword.charAt(0) { if(next chars of sb match next chars of keyword) { insert "&lt;b&gt;" before and "&lt;/b&gt;" after the keyword; size += 7; i += keyword.size() + 7; } } } </code></pre> <p>you might also want to take a look into the Matcher implementation of replaceAll: <a href="http://kickjava.com/src/java/util/regex/Matcher.java.htm" rel="nofollow">http://kickjava.com/src/java/util/regex/Matcher.java.htm</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload