Help with RegEx expression/transformation

Hi ! - am on OH3.2 and am trying to use some output I get from running a python3 command using the exec-binding. The output contains a dump of information from my panasonic cloud AC - and in that, there is a JSON-formatted section, I would like to pick in.

The output I get back from the exec binding when triggering run looks like this:

--- creating token by authenticating
--- raw beginning ---
--- raw ending    ---
--- _get_groups()
--- raw beginning ---
{"iaqStatus":{"statusCode":200},"uiFlg":false,"groupCount":1,"groupList":[{"groupId":123626,"groupName":"My House","deviceList":[{"deviceGuid":"xxxxxxxxxxx","deviceType":"1","deviceName":"xxxxxxxxxxx","permission":2,"summerHouse":2,"iAutoX":false,"nanoe":false,"nanoeStandAlone":false,"autoMode":true,"heatMode":true,"fanMode":true,"dryMode":true,"coolMode":true,"ecoNavi":false,"powerfulMode":true,"quietMode":true,"airSwingLR":true,"autoSwingUD":false,"ecoFunction":0,"temperatureUnit":0,"modeAvlList":{"autoMode":1,"fanMode":1},"parameters":{"operate":0,"operationMode":3,"temperatureSet":30.0,"fanSpeed":0,"fanAutoMode":1,"airSwingLR":2,"airSwingUD":4,"ecoMode":0,"ecoNavi":1,"nanoe":0,"iAuto":0,"actualNanoe":0,"airDirection":1,"ecoFunctionData":0,"lastSettingMode":0}}]}]}
--- raw ending    ---
dryTempMin               : -1

I want to get the (JSON formatted) text data between “— _get_groups()” “— raw beginning —”
and “— raw ending —”. In the example above, that would be the line starting with {"iaqStatus

But how will that REGEX expression look like?

I have tried this in my rule:

val json_dump_string_newValue = transform("REGEX", ".*--- _get_groups()\n--- raw beginning ---\n(\\d*.\\d*)\n--- raw ending    ---.*", panasonicac_get_dump_Output_str.state.toString)

But that doesnt work…

Are you sure it’s UNIX style line endings and not Windows style? Maybe try replacing the \n with .* just in case.

Try simplifying the expression. You really just need a marker for the beginning and the end. You don’t have to over specify it. You want the stuff between the first { and the last } after the first occurrence of the word “groups”.


Note that in OH the REGEX needs to match the whole String, hence the .* at the beginning and the end.

If you are processing this in a rule, maybe you don’t even need the regex.

val parts = panasonicac_get_dump_Output_str.state.toString.split('\n')
val groupsJSON = parts[6]

Thanks Rich ! - it was just what I needed. The REGEX you suggested was not correct (it needed double-backslashes) - but a bit of trial and error helped me fix it. It now looks like this (and works);

val json_dump_string_newValue = transform("REGEX", ".*_get_groups.*(\\{.*\\}).*", panasonicac_get_dump_Output_str.state.toString)

AHHH - no, it didnt work :frowning: I thought so, because I saw an OK formatted JSON result, but it has cut aways something. What I get with the REGEX shown is;


The rest is missing :frowning:

Add more to the closing marker. The JSON ends with }}]}]}

Hmm - still dont get it - and cannot get it working. Perhaps I need to sleep on it :wink: