JavaScript Regex Replace

March 6, 2020

Replace day-2020_04_01 to day/2020-04-01

const output = "day-2020_04_01".replace(/day-(\d{4})_(\d{2})_(\d{2})/, 'day/$1-$2-$3')

Replace page-0001 to page/1

const output = "page-0001".replace(/-0+/g, "/")
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.