# RegEx in function-node

**URL:** <https://discourse.nodered.org/t/regex-in-function-node/58763>\
**Category:** General\
**Tags:** function-node\
**Created:** [21 February 2022 19:06 UTC](https://discourse.nodered.org/t/regex-in-function-node/58763 "2022-02-21T19:06:03Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 February 2022 23:09 UTC](https://discourse.nodered.org/t/regex-in-function-node/58763/21 "2022-02-21T23:09:54Z")

</div>

@Ropper I think you will also have to replace the comma in order for parseFloat to work correctly

```auto
var payload = msg.payload.toString();
payload = payload.split("=")[1];
msg.payload = parseFloat(payload.replace(",", "."));
return msg;

```

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [21 February 2022 23:21 UTC](https://discourse.nodered.org/t/regex-in-function-node/58763/22 "2022-02-21T23:21:31Z")

</div>

You could change your remote command from  
**vcgencmd measure\_temp**  
to  
**vcgencmd measure\_temp | cut -d "=" -f 2**  
which hopefully returns 53.0'C  
or  
**vcgencmd measure\_temp | cut -d "=" -f 2 | cut -d "'" -f 1** # -d doublequote singlequote doublequote  
53.0

Not sure how you would pass those quotes over though, might need to escape them.  
Edit - you don't need to wrap -d = in quotes but you do need the quotes for -d "'"

---

<div class="post-metadata">

**Author:** ![Ropper](https://avatars.discourse-cdn.com/v4/letter/r/a5b964/32.png) [@Ropper](https://discourse.nodered.org/u/Ropper)\
**Post date:** [23 February 2022 23:10 UTC](https://discourse.nodered.org/t/regex-in-function-node/58763/23 "2022-02-23T23:10:41Z")

</div>

Thanks Steve - Probably not a topic question but anyhows - how do I remove the decimal in the temp (send the msg as 2-digit value?

---

<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:** [23 February 2022 23:19 UTC](https://discourse.nodered.org/t/regex-in-function-node/58763/24 "2022-02-23T23:19:20Z")

</div>

you can use `parseInt()` instead of `parseFloat()` .. that will return an integer without the decimal  
and rounded down so 51.7 would become 51.

If you want more "accuracy" you can also use `Math.round()` which rounds to the closest whole number  
Math.round(51.7) will result to 52

---

<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:** [24 April 2022 23:20 UTC](https://discourse.nodered.org/t/regex-in-function-node/58763/25 "2022-04-24T23:20:00Z")

</div>

Closed on 24 April 2022 23:20 UTC

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

[Previous page](https://discourse.nodered.org/t/regex-in-function-node/58763.md?page=1)
