const regex = /Level>(\d+)<\/tank/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('Level>(\\d+)<\\\/tank', 'g')
const str = `This XML file does not appear to have any style information associated with it. The document tree is shown below.
<seqSmartbox xmlns="http://tecson.dev.oilview.de/gateway/xsd" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xsi:schemaLocation="http://tecson.dev.oilview.de/gateway/xsd/smartbox.xsd">
<seqHeader>
<indication>Manuelle Abfrage</indication>
<authCode>03B41236A899</authCode>
<devOperator/>
<devLocation/>
<devID>2-852</devID>
<devVersion>V6.02</devVersion>
</seqHeader>
<seqData>
<seqTanks>
<tankNumber>1</tankNumber>
<tankName>Heizöl</tankName>
<seqTankLevel>
<tankLevel>490</tankLevel>
<tankUnit>L</tankUnit>
</seqTankLevel>
<tankPercent>5</tankPercent>
<seqTankSize>
<tankSize>10000</tankSize>
<tankUnit>L</tankUnit>
</seqTankSize>
<seqTankClear>
<tankClearance>9010</tankClearance>
<tankUnit>L</tankUnit>
</seqTankClear>
</seqTanks>
</seqData>
<seqPara>
<para1>30</para1>
<para2>15</para2>
<para4>0</para4>
<para5>5</para5>
<para9>0</para9>
</seqPara>
</seqSmartbox>`;
// 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