Insert a space in front of capital letter in a string

Hi I’m hoping someone can help

I neeed to insert spaces in front of capital letters in a string. the string contains the name of a country instance for example demRepublicOfCongo. I would like to scan the string and inset spaces before each capital letter so that the contents of the above string would become dem Republic Of Congo, for eaxmple.

I found some code that I thought would help but this doesn’t seem to work. It is posted below. I would be grateful if anyone could tell me where I a going wrong.

thanks

//Works out country name from string
var country:String=counrtyinstance.replace("_mc","");
var re:RegExp = /(?<=[a-z])([A-Z])/g;
var re2:RegExp = /(?<=\w)([A-Z])/g;
country.replace(re," $1")
country.replace(re2," $1")
trace (country);