HTTP Regex Syntax

Does somebody know why this regex isn’t working in combination with the HTTP binding?


(?s)(?<=Temperatur Außen.{293})[0-9,-]+(?=.C)

HTML code:

<tr><td width="22%" height="46"><font color="Gray"><b><nobr>Temperatur Außen</nobr></b></font></td>
<td align="center" width="7%" height="46"><img border="0" src="temp.gif" width="32" height="40"></td>
<td align="center" colspan="7"><table border="1" width="100%">
<td align="center" colspan="3" width="19%"><b><font size="1">aktuell</font></b><br><b><font size="5">7,4°C</font></b></td>
<td align="center" width="11%" colspan="1"><font size="1"><b>Min.</b>(08:20)<br></font><b><font size="4">1,0°C</font></b></td>
<td align="center" width="11%" colspan="1"><font size="1"><b>Max.</b>(14:00)<br></font><b><font size="4">7,4°C</font></b></td>
<td align="center" width="11%" colspan="2"><font size="1"><b>Durchschnitt</b><br></font><b><font size="4">2,5°C</font></b></td></table>
<table border="1" width="100%">


String temp { http="<[<=Temperatur Au.en.{290})[0-9,-]+(?=.C))]" }

I am using the release version of openHAB 2

Is it that the regex isn’t working in combination with the HTTP binding, or that your regex expression is incorrect? You might want to try an online regex tester like this one to help perfect your regex expression.

I tested it already there. Normally Java has a little bit different Regex syntax, so you have to make some changes.
But this version of the Regex doesnt work too.

Might be the ß is unicode? meaning you might need to try Au.{1,2}en …

In the regex you tested, you did not capture the match using ‘(’ and ‘)’. Try that regex with the part of the pattern that matches the temperature value enclosed in parens, like this:

(?s)(?<=Temperatur Au.en.{290})([0-9,-]+)(?=.C)

I would be uncomfortable with the counting of exactly 290 characters following the occurrence of “Temperatur Außen”, but if it works, who am I to question that?

Actually none of the suggested solutions work :confused:
I know that counting the characters isn’t the best solution, but when you have got a better regex/solution I would be really pleased :grin:

In the implementation of the REGEX mapper, ^ and $ are prepended and appended respectively to your regex, so I think we all forgot to provide matching for the remainder of the HTML.

The following matches your entire example text and should capture the current temperature value:

(?s).+?Temperatur Außen.+?([0-9,-]+)°C.*

Im afraid, but this doesnt work too. I always get this message in the log:

transformed response is 'null'

Now I found the problem.
openHAB has a problem with the ß and the ° character. So I replaced these with a "."
So now the RegEx is:

(?s).+?Temperatur Au.en.+?([0-9,-]+).C.*

Thanks for your help :grin: