import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(?!common:)(?:([^\\s\\n]+)\\s+){2}\n\n";
final String string = "common: \"mortalkombat_sonia_rules_abc,\" player: \"Mortal Kombat,\" 22-May-22 \n"
+ "Test1 Test2 Type1 Type2 Type3 X Y HOR1 VER1 Data1 Error1 \n"
+ "r1107 ab-1 abcr0201 222 22 -222 -22 -222 -22 2 2 Testing \n"
+ "r1106 ab-2 abcr0201 222 22 -222 -22 -222 -22 2 2 Testing \n"
+ "c377 ab-3 abcf0402 222 2 -222 -22 -222 -22 2 2 Testing \n"
+ "r632 ab-4 abcd0402 222 22 -222 -22 -222 -22 2 2 Testing";
final String subst = "temp";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE | Pattern.COMMENTS);
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