# JSONata: $replace & /regex/

**URL:** <https://discourse.nodered.org/t/jsonata-replace-regex/72076>\
**Category:** General\
**Created:** [12 December 2022 12:41 UTC](https://discourse.nodered.org/t/jsonata-replace-regex/72076 "2022-12-12T12:41:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielbrunt57](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/danielbrunt57/32/42815_2.png) [@danielbrunt57](https://discourse.nodered.org/u/danielbrunt57)\
**Post date:** [12 December 2022 12:41 UTC](https://discourse.nodered.org/t/jsonata-replace-regex/72076/1 "2022-12-12T12:41:18Z")

</div>

I have this regex in Home Assistant that I want to replicate in NR via JSONata:

```auto
regex_replace(find="^[0:]*",replace="")

```

It replaces leading `0`'s or `:`'s until no match, with null.

I have this so far which doesn't completely work:

```auto
$replace($fromMillis((msg.payload * 1000), '[H01]:[m01]:[s01]' ), /[(0+):]/, '', 3)

```

as it replaces just single occurrences anywhere in the string up to 3 times.

What I want is just replace from the beginning, `0` or `:`, until no match so that...  
'00:01:10' is '1:10'  
'00:10:01' is '10:15'  
'01:01:01': is "1:01:01'

---

<div class="post-metadata">

**Author:** ![danielbrunt57](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/danielbrunt57/32/42815_2.png) [@danielbrunt57](https://discourse.nodered.org/u/danielbrunt57)\
**Post date:** [14 December 2022 01:45 UTC](https://discourse.nodered.org/t/jsonata-replace-regex/72076/2 "2022-12-14T01:45:27Z")

</div>

This seems to be working...

```auto
$replace($fromMillis((msg.payload * 1000), '[H]:[m01]:[s01]' ), /^[0:]*/, '')

```

---

<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:** [28 December 2022 01:45 UTC](https://discourse.nodered.org/t/jsonata-replace-regex/72076/3 "2022-12-28T01:45:28Z")

</div>

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