import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^.*(LIGNE|Espace|Maintien|point|Delta|ENTREE).*\\n";
final String string = "LIGNE Calque: \"506\"\n"
+ " Espace: Espace objet\n"
+ " Maintien = 371b3\n"
+ " de point, X=103620.0722 Y=49245.7502 Z= 0.0000\n"
+ " vers point, X=103620.0705 Y=49187.0630 Z= 0.0000\n"
+ " Longueur = 58.6872, Angle dans le plan XY = 270\n"
+ " Delta X = -0.0016, Delta Y = -58.6872, Delta Z = 0.0000\n"
+ " LIGNE Calque: \"506\"\n"
+ " Espace: Espace objet\n"
+ " Maintien = 371ad\n"
+ " de point, X=103810.0724 Y=49255.0701 Z= 0.0000\n"
+ " vers point, X=103810.0705 Y=49187.0630 Z= 0.0000\n"
+ " Longueur = 68.0071, Angle dans le plan XY = 270\n"
+ " Delta X = -0.0019, Delta Y = -68.0071, Delta Z = 0.0000\n"
+ " LIGNE Calque: \"506\"\n"
+ " Espace: Espace objet\n"
+ " Maintien = 371af\n"
+ " de point, X=104000.0727 Y=49264.3900 Z= 0.0000\n"
+ "Appuyez sur ENTREE pour continuer:\n"
+ " vers point, X=104000.0705 Y=49187.0630 Z= 0.0000\n"
+ " Longueur = 77.3270, Angle dans le plan XY = 270\n"
+ " Delta X = -0.0022, Delta Y = -77.3270, Delta Z = 0.0000\n"
+ " LIGNE Calque: \"506\"\n"
+ " Espace: Espace objet\n"
+ " Maintien = 371a3\n"
+ " de point, X=104190.0722 Y=49246.6876 Z= 0.0000\n"
+ " vers point, X=104190.0705 Y=49187.0630 Z= 0.0000\n"
+ " Longueur = 59.6246, Angle dans le plan XY = 270\n"
+ " Delta X = -0.0017, Delta Y = -59.6246, Delta Z = 0.0000\n"
+ " LIGNE Calque: \"506\"\n"
+ " Espace: Espace objet\n"
+ " Maintien = 3718e\n"
+ " de point, X=104360.0725 Y=49256.5929 Z= 0.0000\n"
+ " vers point, X=104360.0705 Y=49187.0630 Z= 0.0000\n"
+ " Longueur = 69.5299, Angle dans le plan XY = 270\n"
+ " Delta X = -0.0019, Delta Y = -69.5299, Delta Z = 0.0000\n"
+ " LIGNE Calque: \"506\"\n"
+ " Espace: Espace objet\n"
+ "Appuyez sur ENTREE pour continuer:\n"
+ " Maintien = 37190\n"
+ " de point, X=104530.0727 Y=49264.3067 Z= 0.0000\n"
+ " vers point, X=104530.0705 Y=49187.0630 Z= 0.0000\n"
+ " Longueur = 77.2437, Angle dans le plan XY = 270\n"
+ " Delta X = -0.0022, Delta Y = -77.2437, Delta Z = 0.0000\n"
+ " LIGNE Calque: \"506\"\n"
+ " Espace: Espace objet\n"
+ " Maintien = 37192\n"
+ " de point, X=104700.0730 Y=49274.0157 Z= 0.0000\n"
+ " vers point, X=104700.0705 Y=49187.0630 Z= 0.0000\n"
+ " Longueur = 86.9527, Angle dans le plan XY = 270\n"
+ " Delta X = -0.0024, Delta Y = -86.9527, Delta Z = 0.0000\n"
+ " LIGNE Calque: \"506\"\n"
+ " Espace: Espace objet\n"
+ " Maintien = 37194\n"
+ " de point, X=104920.0731 Y=49278.0638 Z= 0.0000\n"
+ " vers point, X=104920.0705 Y=49187.0630 Z= 0.0000\n"
+ " Longueur = 91.0008, Angle dans le plan XY = 270\n"
+ " Delta X = -0.0025, Delta Y = -91.0008, Delta Z = 0.0000\n"
+ "Appuyez sur ENTREE pour continuer:\n"
+ " LIGNE Calque: \"506\"\n"
+ " Espace: Espace objet\n"
+ " Maintien = 37196\n"
+ " de point, X=105140.0731 Y=49278.0638 Z= 0.0000\n"
+ " vers point, X=105140.0705 Y=49187.0630 Z= 0.0000\n"
+ " Longueur = 91.0008, Angle dans le plan XY = 270\n"
+ " Delta X = -0.0025, Delta Y = -91.0008, Delta Z = 0.0000\n"
+ " LIGNE Calque: \"506\"\n"
+ " Espace: Espace objet\n"
+ " Maintien = 37185\n"
+ " de point, X=105428.0731 Y=49278.0638 Z= 0.0000\n"
+ " vers point, X=105428.0705 Y=49187.0630 Z= 0.0000\n"
+ " Longueur = 91.0008, Angle dans le plan XY = 270\n"
+ " Delta X = -0.0025, Delta Y = -91.0008, Delta Z = 0.0000\n"
+ " LIGNE Calque: \"506\"\n"
+ " Espace: Espace objet\n"
+ " Maintien = 37187\n"
+ " de point, X=105728.0731 Y=49278.0638 Z= 0.0000\n"
+ " vers point, X=105728.0705 Y=49187.0630 Z= 0.0000\n"
+ " Longueur = 91.0008, Angle dans le plan XY = 270\n"
+ "Appuyez sur ENTREE pour continuer:\n"
+ " Delta X = -0.0025, Delta Y = -91.0008, Delta Z = 0.0000\n";
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