import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "0\\R+(.+)\\R(?:(?!CDN)(?!^0$)[\\s\\S])+(?:\\RCDN\\$\\h+(\\d+\\.\\d+))?(?:\\RCDN\\$\\h+(\\d+\\.\\d+))?\\R(?:(?!^0$)[\\s\\S])+";
final String string = "\n"
+ "0\n\n"
+ "South Park™: The Stick of Truth™\n"
+ "OVERALL REVIEWS:\n"
+ "OVERWHELMINGLY POSITIVE\n"
+ "RELEASE DATE:\n"
+ "3 MAR, 2014\n"
+ "-75%\n"
+ "CDN$ 39.99\n"
+ "CDN$ 9.99\n"
+ "Add to Cart\n"
+ "RPGComedyAdventureFunnyTurn-Based\n"
+ "Added on 8/9/2020 ( remove )\n\n"
+ "0\n\n"
+ "Grand Theft Auto V\n"
+ "OVERALL REVIEWS:\n"
+ "VERY POSITIVE\n"
+ "RELEASE DATE:\n"
+ "13 APR, 2015\n"
+ "View Details\n"
+ "Open WorldActionMultiplayerAutomobile SimCrime\n"
+ "Added on 1/15/2020 ( remove )\n\n"
+ "0\n\n"
+ "System Shock\n"
+ "OVERALL REVIEWS:\n"
+ "NO USER REVIEWS\n"
+ "RELEASE DATE:\n"
+ "SUMMER 2021\n"
+ "CDN$ 51.49\n"
+ "Add to Cart\n"
+ "ActionAdventureCyberpunkSci-fiImmersive Sim\n"
+ "Added on 6/9/2020 ( remove )\n";
final String subst = "$1 $2 $3\\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