import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\w(?<!\\.)\\n\\w";
final String string = "Quality risk management. A systematic process for the assessment, control,\n"
+ "communication and review of risks to quality across the lifecycle. (ICH Q9)\n\n"
+ "Simulated agents. A material that closely approximates the physical and, where\n"
+ "practical, the chemical characteristics, e.g. viscosity, particle size, pH etc., of the product\n"
+ "under validation.\n\n"
+ "State of control. A condition in which the set of controls consistently provides assurance\n"
+ "of acceptable process performance and product quality.\n\n"
+ "Traditional approach. A product development approach where set points and operating\n"
+ "ranges for process parameters are defined to ensure reproducibility.\n\n"
+ "Worst Case. A condition or set of conditions encompassing upper and lower processing\n"
+ "limits and circumstances, within standard operating procedures, which pose the greatest\n"
+ "chance of product or process failure when compared to ideal conditions. Such conditions\n"
+ "do not necessarily induce product or process failure.\n\n\n"
+ "User requirements Specification (URS). The set of owner, user and engineering\n"
+ "requirements necessary and sufficient to create a feasible design meeting the intended\n"
+ "purpose of the system.";
final String subst = " ";
final Pattern pattern = Pattern.compile(regex);
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