Reputation: 353
I have a date that comes in like this 2023-05-10T21:12:42+00:00
.
To get rid of the +00:00 I do this:
vars:
date1: " {{ item.expires | regex_replace('\\+00:00') }}"
However, when I print date1 it prints out "DATE1::: 2023-05-10T21:05:26"
with a space before 2023.
I then have to do another regex_replace on the date1 variable to get rid of the space in the beginning and assign it to a new variable like this:
date2: "{{ date1 | regex_replace(' ') }}"
I wanted to chain the regex_replace together like this but it didn't work:
date1: " {{ item.expires | regex_replace('\\+00:00') | regex_replace(' ') }}"
Is there a better way to do this?
Upvotes: 0
Views: 207
Reputation: 18351
You are getting extra space because of extra space after the starting double quotes, double quotes preserve the starting space with it.
date1: " {{ item.expires | regex_replace('\\+00:00') }}"
^
^
^
Change this to the following and you will get rid of starting space :
date1: "{{ item.expires | regex_replace('\\+00:00') }}"
Upvotes: 1