Thanks muchly Ritch. The square brackets are needed in JSON to reference a key with spaces in it.
However, I have moved away from using JSON to parse my data because it contains control chars , certainly newlines.
Notwithstanding design decisions as to what where things “should” go, let us focus on the very simple regexp - please - and understand if we can please, why it is not working. It shouldnt matter where the expr is , so lets just use this (bad) example eh, once working I will correct the design.
So I moved to REGEX with a very simple pattern…
(?:“Motor current below expectation”[^a-z]*?)(true|false)
Meaning:
- Non-capturing group (?:“Motor current below expectation”[^a-z]*?)
- “Motor current below expectation” matches the characters “Motor current below expectation” literally (case sensitive)
- Match a single character not present in the list below [^a-z]*?
- *? Quantifier — Matches between zero and unlimited times, as few times as possible, expanding as needed (lazy)
- a-z a single character in the range between a (index 97) and z (index 122) (case sensitive)
- 1st Capturing Group (true|false)
- 1st Alternative true
- true matches the characters true literally (case sensitive)
- 2nd Alternative false
- false matches the characters false literally (case sensitive)
Using the text in the OP , and including newlines and tabs, this expression correctly parses the text.
So the question is, and help needed, why is the regexp not working in OH, because the capture group 1 correctly yields “false”. Whilst the regexpr can be improved to better guard against bad data, it is very simple and works , question is why not in OH? What exactly is OH refusing to parse in the very simple regexp?.
p.s. Ritch,
I do not understand what you mean by:
In that case your expression must match the entire string and only the first group is what gets returned by the transformation. And by entire String I mean the whole thing, not just the line. If your String has multiple lines you must match all of them
`
What is the point of a regexp that must match the entire data, rather than just a string. And what is the “first group” in OH terms?
Regex appears to much different than how it should work, so I will go back to JSON, I’m almost there , because it recognised the structure , from openhab.log
2020-01-13 16:40:56.348 [WARN ] [ofiles.JSonPathTransformationProfile] - Could not transform state '{
"Motor current below expectation": false,
"Motor current always high": false,
"Motor taking too long": false,
"discrepancy between air and pipe sensors": false,
"air sensor out of expected range": false,
"pipe sensor out of expected range": false,
"low power mode is enabled": false,
"no target temperature has been set by host": false,
"valve may be sticking": false,
"valve exercise was successful": false,
"valve exercise was unsuccessful": false,
"driver micro has suffered a watchdog reset and needs data refresh": false,
"driver micro has suffered a noise reset and needs data refresh": false,
"battery voltage has fallen below 2p2V and valve has been opened": false,
"request for heat messaging is enabled": false,
"request for heat": false
}' with function '$.<jsonPath>' and format '<valueFormat>'
Reading this, Problem with spaces in json keys , it appears I need a rule to strip out newlines etc. Blimey, hard work this OH. I will go back to regexpr