import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(<)(\\w+)(,\\s)(.+)(,\\>)";
final String string = "<IccId, nvarchar(50),>\n"
+ " ,<DeliveryNumber, nvarchar(10),>\n"
+ " ,<DeliveryPosition, int,>\n"
+ " ,<ItemCreationDate, smalldatetime,>\n"
+ " ,<PlannedDeliveryDate, smalldatetime,>\n"
+ " ,<CableLength, float,>\n"
+ " ,<CableLengthUm, nvarchar(3),>\n"
+ " ,<GrossWeight, float,>\n"
+ " ,<GrossWeightUm, nvarchar(3),>\n"
+ " ,<NetWeight, float,>\n"
+ " ,<NetWeightUm, nvarchar(3),>\n"
+ " ,<SalesOrganization, nvarchar(4),>\n"
+ " ,<ShipToCode, nvarchar(10),>\n"
+ " ,<ShipToName, nvarchar(40),>\n"
+ " ,<ShipToStreet, nvarchar(60),>\n"
+ " ,<ShipToHouseNumber, nvarchar(10),>\n"
+ " ,<ShipToPostalCode, nvarchar(10),>\n"
+ " ,<ShipToCity, nvarchar(40),>\n"
+ " ,<ShipToCountry, nvarchar(3),>\n"
+ " ,<ShipToRegion, nvarchar(3),>\n"
+ " ,<DeliveryPlantNumber, nvarchar(4),>\n"
+ " ,<CableMaterialCode, nvarchar(18),>\n"
+ " ,<CableBatchNumber, nvarchar(10),>\n"
+ " ,<CableNominalDiameter, float,>\n"
+ " ,<CableNominalDiameterUm, nvarchar(3),>\n"
+ " ,<CableName, nvarchar(40),>\n"
+ " ,<CableProductionDate, smalldatetime,>\n"
+ " ,<CableProductionPlant, nvarchar(4),>\n"
+ " ,<CableSection, float,>\n"
+ " ,<CableSectionUm, nvarchar(3),>\n"
+ " ,<CableSectionMultiplier, float,>\n"
+ " ,<Voltage, float,>\n"
+ " ,<VoltageMu, nvarchar(3),>\n"
+ " ,<DrumNumber, nvarchar(18),>\n"
+ " ,<DrumType, nvarchar(18),>\n"
+ " ,<DrumCoreDiameter, float,>\n"
+ " ,<DrumCoreDiameterUm, nvarchar(3),>\n"
+ " ,<DrumInnerWidth, float,>\n"
+ " ,<DrumInnerWidthUm, nvarchar(3),>\n"
+ " ,<DrumWeight, float,>\n"
+ " ,<DrumWeightUm, nvarchar(3),>\n"
+ " ,<CustomerPurchaseOrderNumber, nvarchar(20),>\n"
+ " ,<CustomerName, nvarchar(35),>\n"
+ " ,<CustomerNumber, nvarchar(10),>\n"
+ " ,<CustomerMaterialNumber, nvarchar(35),>\n"
+ " ,<SalesOrderNumber, nvarchar(10),>\n"
+ " ,<SalesOrderPosition, nvarchar(6),>\n"
+ " ,<TotalSpins, float,>\n";
final String subst = "@$2 $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