const regex = /\s*<GetFulfillmentPreviewResponse[\s\S]*?>[\s\S]*?<GetFulfillmentPreviewResult[\s\S]*?>[\s\S]*?<FulfillmentPreviews[\s\S]*?<EstimatedFees[\s\S]*?<Value>([\s\S]*?)<\/Value>/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\s*<GetFulfillmentPreviewResponse[\\s\\S]*?>[\\s\\S]*?<GetFulfillmentPreviewResult[\\s\\S]*?>[\\s\\S]*?<FulfillmentPreviews[\\s\\S]*?<EstimatedFees[\\s\\S]*?<Value>([\\s\\S]*?)<\\\/Value>', 'gm')
const str = `<GetFulfillmentPreviewResponse xmlns="http://mws.amazonaws.com/FulfillmentOutboundShipment/2010-10-01/">
<GetFulfillmentPreviewResult>
<FulfillmentPreviews>
<member>
<MarketplaceId>ATVPDKIKX0DER</MarketplaceId>
<IsCODCapable>false</IsCODCapable>
<IsFulfillable>true</IsFulfillable>
<ShippingSpeedCategory>Standard</ShippingSpeedCategory>
<UnfulfillablePreviewItems/>
<EstimatedShippingWeight>
<Value>4</Value>
<Unit>POUNDS</Unit>
</EstimatedShippingWeight>
<EstimatedFees>
<member>
<Name>FBAPerUnitFulfillmentFee</Name>
<Amount>
<CurrencyCode>USD</CurrencyCode>
<Value>6.73</Value>
</Amount>
</member>
</EstimatedFees>
<FulfillmentPreviewShipments>
<member>
<LatestShipDate>2019-02-02T07:59:59Z</LatestShipDate>
<LatestArrivalDate>2019-02-05T07:59:59Z</LatestArrivalDate>
<FulfillmentPreviewItems>
<member>
<ShippingWeightCalculationMethod>Dimensional</ShippingWeightCalculationMethod>
<SellerFulfillmentOrderItemId>001test</SellerFulfillmentOrderItemId>
<EstimatedShippingWeight>
<Value>3.228</Value>
<Unit>POUNDS</Unit>
</EstimatedShippingWeight>
<Quantity>1</Quantity>
<SellerSKU>ASICS by Rakuten_20180926_29.86_6799</SellerSKU>
</member>
</FulfillmentPreviewItems>
<EarliestArrivalDate>2019-02-04T08:00:00Z</EarliestArrivalDate>
<EarliestShipDate>2019-01-29T08:00:00Z</EarliestShipDate>
</member>
</FulfillmentPreviewShipments>
</member>
</FulfillmentPreviews>
</GetFulfillmentPreviewResult>
<ResponseMetadata>
<RequestId>8a6d2844-317a-4bc7-9183-e405128203d9</RequestId>
</ResponseMetadata>
</GetFulfillmentPreviewResponse>
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions