# REGEX problem in http binding

**URL:** <https://community.openhab.org/t/regex-problem-in-http-binding/7536>\
**Category:** Beginners\
**Tags:** regex, httpbinding1\
**Created:** [February 14, 2016, 5:06pm UTC](https://community.openhab.org/t/regex-problem-in-http-binding/7536 "2016-02-14T17:06:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![airmax](https://community.openhab.org/letter_avatar_proxy/v4/letter/a/d78d45/32.png) [@airmax](https://community.openhab.org/u/airmax)\
**Post date:** [February 14, 2016, 5:06pm UTC](https://community.openhab.org/t/regex-problem-in-http-binding/7536/1 "2016-02-14T17:06:38Z")

</div>

I have this item configuration:  
`Number Solar_Leistung "Solar [%d W]" <sun> (Solar) {http="<[http://192.168.178.220/min_day.js:60000:REGEX((?<=\\|)(\\d*)(?=\\;))]"}`

I get this log:  
` 7:57:51.127 INFO runtime.busevents[:26] - Solar_Leistung state updated to m[mi++]="14.02.16 17:10:00|0;0;0;964;226;226;21" m[mi++]="14.02.16 17:05:00|0;0;0;964;256;256;22" m[mi++]="14.02.16 17:00:00|0;0;0;964;274;274;22" m[mi++]="14.02.16 16:55:00|0;0;0;964;264;264;22" m[mi++]="14.02.16 16:50:00|0;0;0;964;259;259;22"`

I’m trying to match only the first line and the number between | and ; which is currently 0. I tested my regex on [Java regex testing - RegexPlanet](http://www.regexplanet.com/advanced/java/index.html) and it looked fine to me.

Any advice would be great.

---

<div class="post-metadata">

**Author:** ![guessed](https://community.openhab.org/user_avatar/community.openhab.org/guessed/32/616_2.png) [@guessed](https://community.openhab.org/u/guessed)\
**Post date:** [February 14, 2016, 6:08pm UTC](https://community.openhab.org/t/regex-problem-in-http-binding/7536/2 "2016-02-14T18:08:55Z")

</div>

Something with one capture value, more like:

```auto
.*?\|(\d+);.*

```

… or the Java-escaped variant 😉

`REGEX` adds a `^` and `$` to the beginning/end (resp) of the string supplied, so this will only catch the first value.

EDIT: Here’s an example of it in rule form:

```auto
rule "test regex 4"
when
   Time cron "0/10 * * * * ?"
then
   var VALUE = 'm[mi++]="14.02.16 17:10:00|0;0;0;964;226;226;21"\nm[mi++]="14.02.16 17:05:00|0;0;0;964;256;256;22"\nm[mi++]="14.02.16 17:00:00|0;0;0;964;274;274;22"\nm[mi++]="14.02.16 16:55:00|0;0;0;964;264;264;22"\nm[mi++]="14.02.16 16:50:00|0;0;0;964;259;259;22"'

   logInfo('regex4', 'original=' + VALUE + ' new=' + transform('REGEX', '.*?\\|(\\d+);.*', VALUE))
end

```

and the output:

```auto
10:21:30.005 DEBUG o.o.m.r.i.e.ExecuteRuleJob[:53]- Executing scheduled rule 'test regex 4'
10:21:30.012 DEBUG o.o.c.t.i.s.RegExTransformationService[:42]- about to transform 'm[mi++]="14.02.16 17:10:00|0;0;0;964;226;226;21"
m[mi++]="14.02.16 17:05:00|0;0;0;964;256;256;22"
m[mi++]="14.02.16 17:00:00|0;0;0;964;274;274;22"
m[mi++]="14.02.16 16:55:00|0;0;0;964;264;264;22"
m[mi++]="14.02.16 16:50:00|0;0;0;964;259;259;22"' by the function '.*?\|(\d+);.*'
10:21:30.015 INFO o.openhab.model.script.regex4[:53]- original=m[mi++]="14.02.16 17:10:00|0;0;0;964;226;226;21"
m[mi++]="14.02.16 17:05:00|0;0;0;964;256;256;22"
m[mi++]="14.02.16 17:00:00|0;0;0;964;274;274;22"
m[mi++]="14.02.16 16:55:00|0;0;0;964;264;264;22"
m[mi++]="14.02.16 16:50:00|0;0;0;964;259;259;22" new=0

```

---

<div class="post-metadata">

**Author:** ![airmax](https://community.openhab.org/letter_avatar_proxy/v4/letter/a/d78d45/32.png) [@airmax](https://community.openhab.org/u/airmax)\
**Post date:** [February 15, 2016, 2:18pm UTC](https://community.openhab.org/t/regex-problem-in-http-binding/7536/3 "2016-02-15T14:18:38Z")

</div>

Thanks, it is working in my .item file now.
