# Filtering a number value in a string

**URL:** <https://discourse.nodered.org/t/filtering-a-number-value-in-a-string/84473>\
**Category:** General\
**Created:** [11 January 2024 12:13 UTC](https://discourse.nodered.org/t/filtering-a-number-value-in-a-string/84473 "2024-01-11T12:13:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sneakynuts](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@sneakynuts](https://discourse.nodered.org/u/sneakynuts)\
**Post date:** [11 January 2024 12:13 UTC](https://discourse.nodered.org/t/filtering-a-number-value-in-a-string/84473/1 "2024-01-11T12:13:02Z")

</div>

Using the alexa.remote2 palette, when asking alexa, for example, "Whats the current temperature?"  
This is the response i get in the debug  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/7/a7ccc3658e6138025a5902e4a5adc4db855b3e61.png)  
How do i use a switch node to use like "is between" two values when the answer is in a string??

I can use contains, like this, but i would need alot of outputs to cover a wide temp range  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/8/68054fae12cdd96f03152ba729d9cbc511a628b9.png)

just cant seem to find a way  
cheers

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [11 January 2024 12:36 UTC](https://discourse.nodered.org/t/filtering-a-number-value-in-a-string/84473/2 "2024-01-11T12:36:43Z")

</div>

Quick and dirty way 🙂

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/f/6f23a2691f0e7fe6fdae91e7f1cc09c94311c148.png)

```auto
[{"id":"25d8f339c39a9601","type":"inject","z":"e65ad62fea9fb3f4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Right now, it's 6 degrees Celsius.","payloadType":"str","x":100,"y":1350,"wires":[["3f11c4c89fadca94"]]},{"id":"3f11c4c89fadca94","type":"split","z":"e65ad62fea9fb3f4","name":"","splt":" ","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":230,"y":1350,"wires":[["01b0444ce0f8c06a"]]},{"id":"01b0444ce0f8c06a","type":"switch","z":"e65ad62fea9fb3f4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"btwn","v":"-100","vt":"num","v2":"100","v2t":"num"}],"checkall":"true","repair":false,"outputs":1,"x":370,"y":1350,"wires":[["aa94bb951f8eb1ef"]]},{"id":"aa94bb951f8eb1ef","type":"debug","z":"e65ad62fea9fb3f4","name":"debug 398","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":530,"y":1350,"wires":[]}]

```

split by " "

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/6/b63f222968066608d5beef1915a0dcb1d5770e99.png)  
check if in a range  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/c/5c1452e421faf89fd8acdad4bf3f94e43a5ac5f4.png)

Note - sometimes Alexa can go off on a tangent so other sanity checks would be needed 🙂

---

<div class="post-metadata">

**Author:** ![sneakynuts](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@sneakynuts](https://discourse.nodered.org/u/sneakynuts)\
**Post date:** [11 January 2024 12:41 UTC](https://discourse.nodered.org/t/filtering-a-number-value-in-a-string/84473/3 "2024-01-11T12:41:51Z")

</div>

Thanks...

True about Alexa... I can sort out her tangents in other ways...

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [11 January 2024 12:45 UTC](https://discourse.nodered.org/t/filtering-a-number-value-in-a-string/84473/4 "2024-01-11T12:45:33Z")

</div>

you can also use a Jsonata with a regular expression to pick the number out of the string  
`$match(payload.alexaResponse, /\d\d?/)`

Test Flow

```auto
[{"id":"6a18ea68e6e856fd","type":"inject","z":"54efb553244c241f","name":"alexaResponse 23","props":[{"p":"payload.alexaResponse","v":"Right now, it's 23 degrees Celsius","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":190,"y":3900,"wires":[["8998cf9da4e6531c"]]},{"id":"8998cf9da4e6531c","type":"change","z":"54efb553244c241f","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$match(payload.alexaResponse, /\\d\\d?/)","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"$number(payload.match)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":3940,"wires":[["b23ac979c073ab52"]]},{"id":"b23ac979c073ab52","type":"debug","z":"54efb553244c241f","name":"debug 62","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":3940,"wires":[]},{"id":"676c3c1aab72c28f","type":"inject","z":"54efb553244c241f","name":"alexaResponse 9","props":[{"p":"payload.alexaResponse","v":"Right now, it's 9 degrees Celsius","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":200,"y":3980,"wires":[["8998cf9da4e6531c"]]}]

```

---

<div class="post-metadata">

**Author:** ![sneakynuts](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@sneakynuts](https://discourse.nodered.org/u/sneakynuts)\
**Post date:** [11 January 2024 12:50 UTC](https://discourse.nodered.org/t/filtering-a-number-value-in-a-string/84473/5 "2024-01-11T12:50:45Z")

</div>

Thanks aswell

Most appreciated both of you

Cheers

---

<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:** [11 March 2024 12:50 UTC](https://discourse.nodered.org/t/filtering-a-number-value-in-a-string/84473/6 "2024-03-11T12:50:59Z")

</div>

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