Regex help or idéas

Hi!

I have tried to find a smart solution to filter out some values. Im intressed In controller.door.motorlock.locked the only thing that changes is locked so can I use controller.door.motorlock as a condition? The second thing a want is externalId="ID:20_20181002_150003"

Have someone some smart idéas?

/Niclas

I assume that you are somehow receiving this data in node-RED??

Please attach a debug node and set the node output to show the 'complete msg object', and paste the resulting msg, so we can see it's true format.

This looks like xml, use an xml node and feed the data through it, no need to parse/regex it.

Hi. It comes in like this in node-red and it is xml based.
But the problem is that it comes in chunks so start and end tag is not always included in the payload.
So i can´t use the xml node. I get invalid xml to often.

/Niclas

 id="1509194" name="controller.door.motorlock.locked" type="controller" timestamp="1612423924000" domain="4" domainName="Great Domain"><argument value="LCU" type="controller" id="11"/><argument value="Kundentré" type="dac" id="20" externalId="ID:20_20181002_150003"><![CDATA[address=1]]></argument><argument value="Kundentré" type="door" id="27"/></event></batch><batch name="controller.door.motorlock.locked.batch">```

You could use a change node with jsonata expression

$match(payload,/name=\"(.*?)\".*externalId=\"(.*?)\"/)

output (see groups array):

{"match":"name=\"controller.door.motorlock.locked\" type=\"controller\" timestamp=\"1612423924000\" domain=\"4\" domainName=\"Great Domain\"><argument value=\"LCU\" type=\"controller\" id=\"11\"/><argument value=\"Kundentré\" type=\"dac\" id=\"20\" externalId=\"ID:20_20181002_150003\"","index":13,"groups":["controller.door.motorlock.locked","ID:20_20181002_150003"]}

Example flow:

[{"id":"5906ce56.3e41a8","type":"inject","z":"b7a67819.1a6dd","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"id=\"1509194\" name=\"controller.door.motorlock.locked\" type=\"controller\" timestamp=\"1612423924000\" domain=\"4\" domainName=\"Great Domain\"><argument value=\"LCU\" type=\"controller\" id=\"11\"/><argument value=\"Kundentré\" type=\"dac\" id=\"20\" externalId=\"ID:20_20181002_150003\"><![CDATA[address=1]]></argument><argument value=\"Kundentré\" type=\"door\" id=\"27\"/></event></batch><batch name=\"controller.door.motorlock.locked.batch\">","payloadType":"str","x":336,"y":240,"wires":[["cea5f0bf.edb7c"]]},{"id":"cea5f0bf.edb7c","type":"change","z":"b7a67819.1a6dd","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$match(payload,/name=\\\"(.*?)\\\".*externalId=\\\"(.*?)\\\"/)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":512,"y":240,"wires":[["d291ac93.9cf6a"]]},{"id":"d291ac93.9cf6a","type":"debug","z":"b7a67819.1a6dd","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":718,"y":240,"wires":[]}]

In that case it might be best to save them in node-red and wait for the end tag and join them up before attempting to parse it. This would particularly be a good idea if the data you are looking for might be split between chunks.

Hi again.

The payload is undefined.
Is it coming as an objekt maybe or schould it work anyway?

Thanks for the help so far!

The example flow i posted works. Check how it differs from your input.

That debug is showing two messages. The first has a string in msg.payload, the second does not have anything in msg.payload. You need to work out why you are getting two messages. As suggested earlier, it would be a good idea to set the debug node to show Complete Message, that may give you more information.

Hi again.

Now you see the differens of the inject node and my http listener.
Cant´t really understand why it´s not working. With the inject node it works great.

The lower payload in the debug is the inject node

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.