import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "by([^(b(?>y))])+";
final String string = "zzzzzzzzzzzzzzzzzzeererezzz By LITE-ON!Model: PA-1121-12H, PA-1121-12R!Series: PPP017L!HP Part No.: 316688-001, 394900-001, 393946-001!!By HIPRO!Model: HP-OW121F13!Series: PPP017H!HP Part No.: 316688-002!!By Fordgood!Model: 0309A18120!Series: PPP017S!HP Part No.: 316688-003 !Replace with HP Spare No.: 317188-001!Compatible HP Spare No.: 350775-001!!Input: 110-240V~ 2.5A, 50-60Hz!Output: 18.5V 6.5A 120W!Connecter size: Int. Diameter: 2.50mm Ext. Diameter: 5.50mm Length : 14.00mm!!Dimension: 168 x 62 x 37 mm!!*For use with Presario 3000xx notebook series.!!**Please take note, 3 wire AC power cord not included.!!/by([^(b(?>y))])+/gi";
final String subst = "";
final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
final Matcher matcher = pattern.matcher(string);
// The substituted value will be contained in the result variable
final String result = matcher.replaceAll(subst);
System.out.println("Substitution result: " + result);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html