import java.util.*;
import java.util.regex.*;
import java.lang.*;
import java.io.*;
class Ideone
{
{
String s
= "CGS00607 blahblahblahblah CG00608\nblahblahblah CG00607 blahblah CG00608 blahblahblah\nblahblahblahblah CG00607"; String regex
= "(?s)(\\G(?!^)|CGS00607)(.*?)(CG00607)"; System.
out.
println( s.
replaceAll(regex,
"$1$2<b>$3</b>") ); }
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS51dGlsLnJlZ2V4Lio7CmltcG9ydCBqYXZhLmxhbmcuKjsKaW1wb3J0IGphdmEuaW8uKjsKCmNsYXNzIElkZW9uZQp7CglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbiAoU3RyaW5nW10gYXJncykgdGhyb3dzIGphdmEubGFuZy5FeGNlcHRpb24KCXsKCQlTdHJpbmcgcyA9ICJDR1MwMDYwNyBibGFoYmxhaGJsYWhibGFoIENHMDA2MDhcbmJsYWhibGFoYmxhaCBDRzAwNjA3IGJsYWhibGFoIENHMDA2MDggYmxhaGJsYWhibGFoXG5ibGFoYmxhaGJsYWhibGFoIENHMDA2MDciOwoJCVN0cmluZyByZWdleCA9ICIoP3MpKFxcRyg/IV4pfENHUzAwNjA3KSguKj8pKENHMDA2MDcpIjsKICAgCQlTeXN0ZW0ub3V0LnByaW50bG4oIHMucmVwbGFjZUFsbChyZWdleCwgIiQxJDI8Yj4kMzwvYj4iKSApOwoJfQp9