javascript – Regex How to match the first 2 instances of a specific character for Date Time string
In JavaScript, I have a date format like this:
2023-11-02 10:00:00 -0700
I want to only match the first two instances of the - signs between the 2023-11-02, but not match the - in front of the -0700, and then replace it with / so that the final output would be
2023/11/02 10:00:00 -0700
I tried doing a regex match:
("2023-11-02 10:00:00 -0700").replace(/[^\d\:\ ]{1,2}/g, "https://stackoverflow.com/"); but still matching the - in front of the -0700, and the output is '2023/11/02 10:00:00 /0700' which is invalid.
Read more here: Source link
