fork(1) download
  1. import java.util.*;
  2. import java.util.regex.*;
  3. import java.lang.*;
  4. import java.io.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String s = "CGS00607 blahblahblahblah CG00608\nblahblahblah CG00607 blahblah CG00608 blahblahblah\nblahblahblahblah CG00607";
  11. String regex = "(?s)(\\G(?!^)|CGS00607)(.*?)(CG00607)";
  12. System.out.println( s.replaceAll(regex, "$1$2<b>$3</b>") );
  13. }
  14. }
Success #stdin #stdout 0.12s 53904KB
stdin
Standard input is empty
stdout
CGS00607 blahblahblahblah CG00608
blahblahblah <b>CG00607</b> blahblah CG00608 blahblahblah
blahblahblahblah <b>CG00607</b>