import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(?!MsgBox\\().*(*SKIP)(*F)|(?:(?:.{1,70}|.{71,140}|.{141,210}|.{211,280})|\\G(?!^))\\S+\\K\\h(?=.{25,}$)";
final String string = "'Some looooooong comment Lorem ipsum dolor sit amet, consectetur adipiscing \n"
+ "'elit. Ut a volutpat dolor. In risus odio, pharetra a arcu in, efficitur \n"
+ "'ornare lectus. Maecenas non aliquet leo. Praesent luctus blandit \n"
+ "'magna, et sagittis ex porta et.\n"
+ "MsgBox(\"Some text in MsgBox. Donec vulputate eros ac nulla hendrerit auctor. In hac habitasse platea dictumst. Proin fermentum augue elit, eget consequat massa mattis et. Integer semper imperdiet diam sit amet malesuada.\", 64, \"Title of MsgBox\")\n"
+ "'Another comment now with link to doc. \n"
+ "'https://example.com/?bs64=SWYgeW91IGFyZSBzbWFydCBlbm91Z2ggdG8gZGVjb2RlLCB5b3UgbXVzdCBkZWZpbml0ZWx5IHdhdGNoIHRoaXM6IGh0dHBzOi8vd3d3LnlvdXR1YmUuY29tL3dhdGNoP3Y9b0hnNVNKWVJIQTA=";
final String subst = " \" _\\n & \"";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
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