# Regex help or idéas

**URL:** <https://discourse.nodered.org/t/regex-help-or-ideas/40337>\
**Category:** General\
**Created:** [3 February 2021 21:20 UTC](https://discourse.nodered.org/t/regex-help-or-ideas/40337 "2021-02-03T21:20:51Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![niclas.w82](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/niclas.w82/32/31813_2.png) [@niclas.w82](https://discourse.nodered.org/u/niclas.w82)\
**Post date:** [3 February 2021 21:20 UTC](https://discourse.nodered.org/t/regex-help-or-ideas/40337/1 "2021-02-03T21:20:51Z")

</div>

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?

 ![Skärmavbild 2021-02-03 kl. 22.00.18](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/a/0a27114070cbe252a1be1d61da52c3fe5d173e9c.jpeg)

/Niclas

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [3 February 2021 21:56 UTC](https://discourse.nodered.org/t/regex-help-or-ideas/40337/2 "2021-02-03T21:56:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [4 February 2021 04:08 UTC](https://discourse.nodered.org/t/regex-help-or-ideas/40337/3 "2021-02-04T04:08:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![niclas.w82](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/niclas.w82/32/31813_2.png) [@niclas.w82](https://discourse.nodered.org/u/niclas.w82)\
**Post date:** [4 February 2021 07:38 UTC](https://discourse.nodered.org/t/regex-help-or-ideas/40337/4 "2021-02-04T07:38:41Z")

</div>

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

````auto
 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">```
````

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [4 February 2021 07:46 UTC](https://discourse.nodered.org/t/regex-help-or-ideas/40337/5 "2021-02-04T07:46:37Z")

</div>

You could use a change node with jsonata expression

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

```

output (see groups array):

```auto
{"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:

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [4 February 2021 08:09 UTC](https://discourse.nodered.org/t/regex-help-or-ideas/40337/6 "2021-02-04T08:09:12Z")

</div>

> [@niclas.w82](#):
>
> the problem is that it comes in chunks so start and end tag is not always included in the payload.

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.

---

<div class="post-metadata">

**Author:** ![niclas.w82](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/niclas.w82/32/31813_2.png) [@niclas.w82](https://discourse.nodered.org/u/niclas.w82)\
**Post date:** [4 February 2021 09:11 UTC](https://discourse.nodered.org/t/regex-help-or-ideas/40337/7 "2021-02-04T09:11:20Z")

</div>

Hi again.

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

 ![payload2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/6/a6d5cbd38317396ab60db6c5bd3844dc840a9af5.jpeg)

Thanks for the help so far!

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [4 February 2021 09:58 UTC](https://discourse.nodered.org/t/regex-help-or-ideas/40337/8 "2021-02-04T09:58:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [4 February 2021 10:09 UTC](https://discourse.nodered.org/t/regex-help-or-ideas/40337/9 "2021-02-04T10:09:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![niclas.w82](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/niclas.w82/32/31813_2.png) [@niclas.w82](https://discourse.nodered.org/u/niclas.w82)\
**Post date:** [4 February 2021 12:32 UTC](https://discourse.nodered.org/t/regex-help-or-ideas/40337/10 "2021-02-04T12:32:57Z")

</div>

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

 ![payload3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd5d0fce7a0e3dbf4326a1c4c3d79fb06806b2eb.jpeg)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 April 2021 12:33 UTC](https://discourse.nodered.org/t/regex-help-or-ideas/40337/11 "2021-04-05T12:33:52Z")

</div>

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