# OH 3 - Profile- Transformations - regex

**URL:** <https://community.openhab.org/t/oh-3-profile-transformations-regex/121630>\
**Category:** Scripts & Rules\
**Tags:** regex-transform, profiles, openhab3\
**Created:** [April 30, 2021, 7:13am UTC](https://community.openhab.org/t/oh-3-profile-transformations-regex/121630 "2021-04-30T07:13:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![markusth](https://community.openhab.org/user_avatar/community.openhab.org/markusth/32/39845_2.png) [@markusth](https://community.openhab.org/u/markusth)\
**Post date:** [April 30, 2021, 7:13am UTC](https://community.openhab.org/t/oh-3-profile-transformations-regex/121630/1 "2021-04-30T07:13:38Z")

</div>

I try to scrape covid-19 numbers from the RKI webpage here [RKI - Coronavirus SARS-CoV-2 - COVID-19: Fallzahlen in Deutschland und weltweit](https://www.rki.de/DE/Content/InfAZ/N/Neuartiges_Coronavirus/Fallzahlen.html/) which doesn’t work as expected. When I test my expression here [regex101: build, test, and debug regex](https://regex101.com/)

expression to test: `/Gesamt<\/strong><\/td><td class="right" colspan="1" rowspan="1"><strong>([\d\.]+)/gm`

I get the result: 1 match, 1 group

Which is what I do want. I tried several alternatives to get this transform working in a profile setting in the UI in OH3, this is what I entered in the “Profile Configuration - Regular Expression” field:

`Gesamt<\\/strong><\\/td><td class=\"right\" colspan=\"1\" rowspan=\"1\"><strong>([\\d\\.]+)`

`Gesamt<\\/strong><\\/td><td class="right" colspan="1" rowspan="1"><strong>([\\d\\.]+)`

`Gesamt<\\\/strong><\\\/td><td class=\"right\" colspan=\"1\" rowspan=\"1\"><strong>([\\\d\\\.]+)`

`Gesamt<\/strong><\/td><td class="right" colspan="1" rowspan="1"><strong>([\d\.]+)`

options with leading “/” and trailing “/gm” I tried as well. Unfortunately none of them worked. The only thing I got working is default Profile with no transformation, which give me the whole HTML result. I wonder what I might do wrong and hope someone here is able to guide me.

Thanks in advance  
Markus

---

<div class="post-metadata">

**Author:** ![glhopital](https://community.openhab.org/user_avatar/community.openhab.org/glhopital/32/91632_2.png) [@glhopital](https://community.openhab.org/u/glhopital)\
**Post date:** [April 30, 2021, 7:59am UTC](https://community.openhab.org/t/oh-3-profile-transformations-regex/121630/2 "2021-04-30T07:59:34Z")

</div>

Have you seen that it already exists a binding for this [here](https://www.openhab.org/addons/bindings/coronastats/) ?

---

<div class="post-metadata">

**Author:** ![markusth](https://community.openhab.org/user_avatar/community.openhab.org/markusth/32/39845_2.png) [@markusth](https://community.openhab.org/u/markusth)\
**Post date:** [April 30, 2021, 8:46am UTC](https://community.openhab.org/t/oh-3-profile-transformations-regex/121630/3 "2021-04-30T08:46:52Z")

</div>

Yes, I did and already tried it. Unfortunately it doesn’t fit my needs. Besides that fact, I do have other usecases where working regex profile transformation is needed. Just picked that one because of public availability of the source.

Nevertheless thanks for mentioning!

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [April 30, 2021, 9:41am UTC](https://community.openhab.org/t/oh-3-profile-transformations-regex/121630/4 "2021-04-30T09:41:00Z")

</div>

_openHAB REGEX Transformation Service_ is not fully featured regex. An obvious limitation, because of the uses it is intended for (e.g. manipulating a single Item state), it can only return **one** match - no arrays or similar.

---

<div class="post-metadata">

**Author:** ![markusth](https://community.openhab.org/user_avatar/community.openhab.org/markusth/32/39845_2.png) [@markusth](https://community.openhab.org/u/markusth)\
**Post date:** [April 30, 2021, 11:11am UTC](https://community.openhab.org/t/oh-3-profile-transformations-regex/121630/5 "2021-04-30T11:11:06Z")

</div>

Does this mean my match need to be my capture and I need to rewrite my expression to fit these requirement? Because currently I do have only one number value captured, but it is different from the match.

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [April 30, 2021, 12:00pm UTC](https://community.openhab.org/t/oh-3-profile-transformations-regex/121630/6 "2021-04-30T12:00:46Z")

</div>

Maybe this willhelp

> [@Textual configuration: html binding and RegEx](https://community.openhab.org/t/textual-configuration-html-binding-and-regex/121150/3):
>
> tldr; to match a float between the strings “start” end “end” use [stateTransformation=“REGEX:.\*?start([+-]?([0-9]\*[\\.])?[0-9]+)?end.\*”] Explaination The problem is that regex with openhab does not behave like e.g. [regex101.com](http://regex101.com). OpenHAB RegEx is greedy and needs to match the whole string. I give an example. Greedy means that the RegEx algorithm tries to to return a string that is as long as possible. Think of it as if it starts from the end of the string and tries to find a match working …

---

<div class="post-metadata">

**Author:** ![s0170071](https://community.openhab.org/user_avatar/community.openhab.org/s0170071/32/20561_2.png) [@s0170071](https://community.openhab.org/u/s0170071)\
**Post date:** [April 30, 2021, 1:57pm UTC](https://community.openhab.org/t/oh-3-profile-transformations-regex/121630/7 "2021-04-30T13:57:05Z")

</div>

I grab most number from a json source, except one, that is RegEx  
My Corona set up is:

.things file:

```auto

Thing http:url:lubu "Lubu CoVid-19" [baseURL="https://www.ludwigsburg.de/start/rathaus+und+service/", refresh="600", timeout="3000"] {
    Channels:
        Type string : Channel_Corona_S_Ludwigsburg_Incidence "S LB 7d [%s]" [stateExtension="corona+7-tage-inzidenz.html", stateTransformation="REGEX:.*?<br>Stadt Ludwigsburg ([+-]?([0-9]*[,])?[0-9]+)?.*"]
}

Thing http:url:rki "RKI CoVid-19" [baseURL="https://api.corona-zahlen.org/", commandMethod="GET", delay="500", refresh="600", timeout="1000"] {
    Channels:
        Type number : Channel_Corona_LK_Ludwigsburg_Incidence "LK LB 7d [%.1f]" [stateExtension="districts", stateTransformation="JSONPATH:$.data.08118.weekIncidence"]
        Type number : Channel_Corona_Berlin_Incidence "ST Berlin Treptow 7d [%.1f]" [stateExtension="districts", stateTransformation="JSONPATH:$.data.11009.weekIncidence"]
        Type number : Channel_Corona_SK_Saarbruecken_Incidence "LK SB 7d [%.1f]" [stateExtension="districts", stateTransformation="JSONPATH:$.data.10041.weekIncidence"]
        Type number : Channel_Corona_S_Weiden_Incidence "Stadt Weiden 7d [%.1f]" [stateExtension="districts", stateTransformation="JSONPATH:$.data.09363.weekIncidence"]
        Type number : Channel_Corona_Deutschland_Incidence "Deutschland 7d [%.1f]" [stateExtension="germany", stateTransformation="JSONPATH:$.weekIncidence"]
        Type number : Channel_Corona_Deutschland_R "Deutschland R [%.2f]" [stateExtension="germany", stateTransformation="JSONPATH:$.r.value"]
}

```

.items file

```auto
 
Group gCorona (gHaus)
String Corona_S_Ludwigsburg_Incidence "S Ludwigsburg 7d [%s]" <line> (gCorona) ["Corona","Measurement"] {channel="http:url:lubu:Channel_Corona_S_Ludwigsburg_Incidence", expire="12h"}
Number Corona_LK_Ludwigsburg_Incidence "LK Ludwigsburg 7d [%.1f]" <line> (gCorona) ["Corona","Measurement"] {channel="http:url:rki:Channel_Corona_LK_Ludwigsburg_Incidence", expire="12h"}
Number Corona_Berlin_Incidence "Berlin Treptow 7d [%.1f]" <line> (gCorona) ["Corona","Measurement"] {channel="http:url:rki:Channel_Corona_Berlin_Incidence", expire="12h"}
Number Corona_SK_Saarbruecken_Incidence "Saarbrücken 7d [%.1f]" <line> (gCorona) ["Corona","Measurement"] {channel="http:url:rki:Channel_Corona_SK_Saarbruecken_Incidence", expire="12h"}
Number Corona_S_Weiden_Incidence "Weiden 7d [%.1f]" <line> (gCorona) ["Corona","Measurement"] {channel="http:url:rki:Channel_Corona_S_Weiden_Incidence", expire="12h"}
Number Corona_Deutschland_Incidence "Deutschland 7d [%.1f]" <line> (gCorona) ["Corona","Measurement"] {channel="http:url:rki:Channel_Corona_Deutschland_Incidence", expire="12h"}
Number Corona_Deutschland_R "Deutschland R [%.1f]" <chart> (gCorona) ["Corona","Measurement"] {channel="http:url:rki:Channel_Corona_Deutschland_R", expire="12h"}

 

```

.sitemap file

```auto

sitemap corona label="Corona" {
  Default item= gCorona
}

```
