import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<=\\S)(?<!\\bAbstract)\\n(?=\\S)";
final String string = "Balanced Quantum Classical Evolutionary Algorithm(BQCEA)\n\n"
+ "Muhammad Shahid, Hasan Mujtaba, Muhammad Asim, Omer Beg\n\n"
+ "Abstract\n"
+ "With advancement in Quantum computing, classical algorithms are adapted and integrated\n"
+ "with Quantum properties such as qubit representation and entanglement. Although these\n"
+ "properties perform better however pre-mature convergence is the main issue in Quantum\n"
+ "Evolutionary Algorithms(QEA) because QEA uses only the best individual to update quan-\n"
+ "tum population. In this paper, we introduced a new way to update the quantum population\n"
+ "of QEA to avoid premature convergence\n\n"
+ "'Balanced Quantum Classical Evolutionary Algorithm(BQCEA)\\n\\nMuhammad Shahid, Hasan Mujtaba, \n"
+ "Muhammad Asim, Omer Beg\\n\\nAbstract\\nWith advancement in Quantum computing, classical \n"
+ "algorithms are adapted and integrated\\nwith Quantum properties such as qubit representation \n"
+ "and entanglement', ' Although these\\nproperties perform better however pre-mature \n"
+ "convergence is the main issue in Quantum\\nEvolutionary Algorithms(QEA) because QEA uses only \n"
+ "the best individual to update quan-\\ntum population', ' In this paper, we introduced a new \n"
+ "way to update the quantum population\\nof QEA to avoid premature convergence',";
final String subst = " ";
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