const regex = new RegExp('<(.+)>([^<>]*)</\\1>', 'gm')
const str = ` <Interceptor>
<AttackCoords>-80.03107887624853,25.351308629611</AttackCoords>
<Outcome>Interdiction</Outcome>
<Infiltrators>6</Infiltrators>
<Enforcer>Assured</Enforcer>
<ActionDate>2013-11-03</ActionDate>
<ActionTime>04:40:00</ActionTime>
<RecordNotes>Infiltrators:
Savanna Carrera,
Gregoria Farías,
Julina Abeyta,
Mariquita Alonso,
Urbano Briseño,
Victoro Montano </RecordNotes>
<NumEscaped>3</NumEscaped>
<LaunchCoords></LaunchCoords>
<AttackVessel>Raft</AttackVessel>
</Interceptor>`;
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