const regex = /<RawData>55014B467FFF0C10BEFF00+<\/RawData>\n\n<PrimaryValue>(\d+.\d+)/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('<RawData>55014B467FFF0C10BEFF00+<\\\/RawData>\\n\\n<PrimaryValue>(\\d+.\\d+)', 'g')
const str = `<?xml version="1.0" encoding="UTF-8"?>
-<Devices-Detail-Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.embeddeddatasystems.com/schema/owserver">
<PollCount>71</PollCount>
<DevicesConnected>2</DevicesConnected>
<LoopTime>2.048</LoopTime>
<DevicesConnectedChannel1>2</DevicesConnectedChannel1>
<DevicesConnectedChannel2>0</DevicesConnectedChannel2>
<DevicesConnectedChannel3>0</DevicesConnectedChannel3>
<DataErrorsChannel1>0</DataErrorsChannel1>
<DataErrorsChannel2>0</DataErrorsChannel2>
<DataErrorsChannel3>0</DataErrorsChannel3>
<VoltageChannel1>4.81</VoltageChannel1>
<VoltageChannel2>4.81</VoltageChannel2>
<VoltageChannel3>4.80</VoltageChannel3>
<VoltagePower>5.05</VoltagePower>
<DeviceName>OWServer_v2-Enet</DeviceName>
<HostName>EDSOWSERVER2</HostName>
<MACAddress>00:04:A3:BE:A9:F2</MACAddress>
<DateTime>2017-03-10 23:18:40</DateTime>
-<owd_DS18B20 Description="Programmable resolution thermometer">
<Name>DS18B20</Name>
<Family>28</Family>
<ROMId>690516B3FC14FF28</ROMId>
<Health>7</Health>
<Channel>1</Channel>
<RawData>54014B467FFF0C10FDFF0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</RawData>
<PrimaryValue>21.2500 Deg C</PrimaryValue>
<Temperature Units="Centigrade">21.2500</Temperature>
<UserByte1 Writable="True">75</UserByte1>
<UserByte2 Writable="True">70</UserByte2>
<Resolution>12</Resolution>
<PowerSource>255</PowerSource>
</owd_DS18B20>
-<owd_DS18B20 Description="Programmable resolution thermometer">
<Name>DS18B20</Name>
<Family>28</Family>
<ROMId>020316B4A6C3FF28</ROMId>
<Health>7</Health>
<Channel>1</Channel>
<RawData>55014B467FFF0C10BEFF0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</RawData>
<PrimaryValue>21.3125 Deg C</PrimaryValue>
<Temperature Units="Centigrade">21.3125</Temperature>
<UserByte1 Writable="True">75</UserByte1>
<UserByte2 Writable="True">70</UserByte2>
<Resolution>12</Resolution>
<PowerSource>255</PowerSource>
</owd_DS18B20>
</Devices-Detail-Response>`;
// 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