Javascript – How to insert certain character[s] only if capturing group isn't empty?
Given are these strings: var string1 = "Chapter_1"; var string2 = "Chapter_1a"; The desired result is: "Chapter 1." "Chapter 1. a)" I could to this: var string1new = string1.replace("_", " ").replace(/(d+)/, "$1.").replace(/.(w)$/, ". $1)")); var string2new = string2.replace("_", " ").replace(/(d+)/,…