// include the latest version of the regex crate in your Cargo.toml
extern crate regex;
use regex::Regex;
fn main() {
let regex = Regex::new(r"(?m)(<)(\w+)(,\s)(.+)(,\>)").unwrap();
let string = "<IccId, nvarchar(50),>
,<DeliveryNumber, nvarchar(10),>
,<DeliveryPosition, int,>
,<ItemCreationDate, smalldatetime,>
,<PlannedDeliveryDate, smalldatetime,>
,<CableLength, float,>
,<CableLengthUm, nvarchar(3),>
,<GrossWeight, float,>
,<GrossWeightUm, nvarchar(3),>
,<NetWeight, float,>
,<NetWeightUm, nvarchar(3),>
,<SalesOrganization, nvarchar(4),>
,<ShipToCode, nvarchar(10),>
,<ShipToName, nvarchar(40),>
,<ShipToStreet, nvarchar(60),>
,<ShipToHouseNumber, nvarchar(10),>
,<ShipToPostalCode, nvarchar(10),>
,<ShipToCity, nvarchar(40),>
,<ShipToCountry, nvarchar(3),>
,<ShipToRegion, nvarchar(3),>
,<DeliveryPlantNumber, nvarchar(4),>
,<CableMaterialCode, nvarchar(18),>
,<CableBatchNumber, nvarchar(10),>
,<CableNominalDiameter, float,>
,<CableNominalDiameterUm, nvarchar(3),>
,<CableName, nvarchar(40),>
,<CableProductionDate, smalldatetime,>
,<CableProductionPlant, nvarchar(4),>
,<CableSection, float,>
,<CableSectionUm, nvarchar(3),>
,<CableSectionMultiplier, float,>
,<Voltage, float,>
,<VoltageMu, nvarchar(3),>
,<DrumNumber, nvarchar(18),>
,<DrumType, nvarchar(18),>
,<DrumCoreDiameter, float,>
,<DrumCoreDiameterUm, nvarchar(3),>
,<DrumInnerWidth, float,>
,<DrumInnerWidthUm, nvarchar(3),>
,<DrumWeight, float,>
,<DrumWeightUm, nvarchar(3),>
,<CustomerPurchaseOrderNumber, nvarchar(20),>
,<CustomerName, nvarchar(35),>
,<CustomerNumber, nvarchar(10),>
,<CustomerMaterialNumber, nvarchar(35),>
,<SalesOrderNumber, nvarchar(10),>
,<SalesOrderPosition, nvarchar(6),>
,<TotalSpins, float,>
";
let substitution = "@$2 $4";
// result will be a String with the substituted value
let result = regex.replace_all(string, substitution);
println!("{}", 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 Rust, please visit: https://docs.rs/regex/latest/regex/