# Help with switch node expression

**URL:** <https://discourse.nodered.org/t/help-with-switch-node-expression/73145>\
**Category:** General\
**Created:** [4 January 2023 08:26 UTC](https://discourse.nodered.org/t/help-with-switch-node-expression/73145 "2023-01-04T08:26:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![network\_potato](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@network\_potato](https://discourse.nodered.org/u/network_potato)\
**Post date:** [4 January 2023 08:26 UTC](https://discourse.nodered.org/t/help-with-switch-node-expression/73145/1 "2023-01-04T08:26:37Z")

</div>

I have a property that is a string. I only want to let the message thorugh the switch node if the number after the second dash `-` is **1**.

A string that would pass looks like this:

PP-12345- **1**

A string that would not pass looks like this:

PP-12345- **2** -4-1

If I select "contains" and put in -1 the it also matches every message that has 1 after the _first_ dash, which is not what I want.

Can anyone help me with this?

---

<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 January 2023 08:37 UTC](https://discourse.nodered.org/t/help-with-switch-node-expression/73145/2 "2023-01-04T08:37:55Z")

</div>

~~edit~~ I misread your issue.

Let me retry.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/1/211939d21416c1dffbfb43fa0b098f5f8ab3185d.png)

`$split(msg.payload,"-")[2]`  
Using a jsonata expression, split the incoming payload, get the 2nd element (starting from 0), if equal to 1, pass message

---

<div class="post-metadata">

**Author:** ![network\_potato](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@network\_potato](https://discourse.nodered.org/u/network_potato)\
**Post date:** [5 January 2023 11:52 UTC](https://discourse.nodered.org/t/help-with-switch-node-expression/73145/3 "2023-01-05T11:52:13Z")

</div>

Anyone else know? 🙂

---

<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:** [5 January 2023 12:09 UTC](https://discourse.nodered.org/t/help-with-switch-node-expression/73145/4 "2023-01-05T12:09:10Z")

</div>

I gave you a solution ?

---

<div class="post-metadata">

**Author:** ![network\_potato](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@network\_potato](https://discourse.nodered.org/u/network_potato)\
**Post date:** [11 January 2023 18:56 UTC](https://discourse.nodered.org/t/help-with-switch-node-expression/73145/5 "2023-01-11T18:56:20Z")

</div>

Yes you did, sorry. It works perfectly, thanks!

---

<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:** [25 January 2023 18:57 UTC](https://discourse.nodered.org/t/help-with-switch-node-expression/73145/6 "2023-01-25T18:57:06Z")

</div>

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