Hi,
I already wrote a lot of topics but do not get it working like i want.
I have a local webpage containing some HTML Text
Example:
<div>
<tr >
<td>502000026870-1 </td>
<td> 30 W </td>
<td rowspan=4 style='vertical-align: middle;'> 50.0 Hz </td>
<td> A: 223 V </td>
<td rowspan=4 style='vertical-align: middle;'> 23 °C </td>
<td rowspan=4 style='vertical-align: middle;'> 2021-08-18 09:35:45
</td>
</tr>
<tr >
<td>502000026870-2 </td>
<td> 30 W </td>
<td> B: 223 V </td>
</tr>
<tr >
<td>502000026870-3 </td>
<td> 29 W </td>
<td> C: 223 V </td>
</tr>
<tr >
<td>502000026870-4 </td>
<td> 2 W </td>
<td>- </td>
</tr>
</div>
</tbody>
</table>
</div> </div>
</div>
</article>
</div>
</section>
I am interested in getting the Values in W contained.
Using https://regex101.com/ i found that the REGEX .\d+.W.</td> should match my values.
I’m using OH3 and have created an HTTP thing
I have created a Channel with a Transformation
I have installed REGEX and JS Transformations and in the Transformation folder i have wrote this :
(function(i) {
var re = new RegExp("<td>.\d+.W.<\/td></td>");
var out = i.match(re)[1];
return parseFloat(out.replace(',', '.'));
})(input)
But i do net get the values i need, the error is:
Executing transformation ChannelStateTransformation{pattern=‘sol.js’, serviceName=‘JS’} failed: An error occurred while executing script. TypeError: Cannot get property “1” of null in at line number 3
I understand the error means that Regex do not find a value, but i’m not able to solve it.
Could you help me?