import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(\\[)(\\d+)(\\].*')(.+)(')";
final String string = " [1] = 0 'NumProgPlc' \n"
+ " [2] = 3 'PadCode' \n"
+ " [3] = 2 'TablePos' \n"
+ " [4] = 1 'CurrentTool' \n"
+ " [5] = 0 'Loc. Override' \n"
+ " [10] = .200000 'PlaceDelay' \n"
+ " [11] = .300000 'PickDelay' \n"
+ " [12] = .150000 'ChamfersChkDelay' \n"
+ " [15] = -107.575500 'xLpos' \n"
+ " [16] = 398.586304 'yLpos' \n"
+ " [17] = 277.373779 'zLpos' \n"
+ " [18] = 90.000000 'RotApproNasAlim' \n"
+ " [21] = 53 'PR Offset Tavola' \n"
+ " [22] = 110 'PR Sopra Tavola' \n"
+ " [23] = 267 'DO Magnete ON' \n"
+ " [24] = 268 'DO Magnete OFF' \n"
+ " [25] = 243 'DI PresPastTav' \n"
+ " [26] = 247 'DI PezNoPrelTav' \n"
+ " [27] = 1 'DO Soffio' \n"
+ " [28] = 111 'PR Tavola+20' \n"
+ " [29] = 112 'PR Tavola' \n"
+ " [30] = 0 '_Prelevato' \n"
+ " [31] = 0 '_ScartoTav' \n"
+ " [32] = 0 '_ScartoCtrlUs' \n"
+ " [33] = 0 '_ScambioTav' \n"
+ " [34] = 0 '_CaricoTav' \n"
+ " [35] = 1 'FlagMemPtoNasAli' \n"
+ " [36] = 244 'DO PezPrelTav' \n"
+ " [37] = 243 'DO PezScamTav' \n"
+ " [38] = 242 'DO PezDepoTav' \n"
+ " [39] = 132 'PR Tavola+50' \n"
+ " [45] = 229 'DI PezPrelNas' \n"
+ " [46] = 1 'OK_PRL' \n"
+ " [50] = 1 'PrioritaNas' \n"
+ " [51] = 0 'CaricoNas' \n"
+ " [55] = 0 'Conveyor2Rot180' \n"
+ " [200] = 3.216000 'TC' \n";
final String subst = "R\\t\\2\\t\\4";
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