fork(6) download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. class TestClass {
  5.  
  6. private static final Pattern MY_PATTERN = Pattern.compile("my|regex");
  7.  
  8. public static void main(final String args[]) {
  9. final StringBuilder builder = new StringBuilder("This is my, not your, regex!");
  10.  
  11. final Matcher m = TestClass.MY_PATTERN.matcher(builder);
  12. builder.replace(0, builder.length(), m.replaceAll("<b>$0</b>"));
  13.  
  14. System.out.println(builder);
  15. }
  16.  
  17. }
  18.  
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
This is <b>my</b>, not your, <b>regex</b>!