You can just add a space before every uppercase character and trim off the leading and trailing spaces
s = s.replace(/([A-Z])/g, ' $1').trim()
You can just add a space before every uppercase character and trim off the leading and trailing spaces
s = s.replace(/([A-Z])/g, ' $1').trim()