I have a text area with a list of roman numerals that I want to convert to arabic digits with a button click. How can I replace only the whole numbers and not parts of the other numbers. For example, I have:
XI
XXI
XXXI
and I get
11
X11
XX11
but I want
11
XXI
XXXI
The code I'm using is:
function romanToArabic() {
var str = document.getElementById("textArea").value;
var mapObj = {
XI:"11",
V:"5"
};
var re = new RegExp(Object.keys(mapObj).join("|"),"gi");
str = str.replace(re, function(matched){
return mapObj[matched];
});
document.getElementById("textArea").value = str;
}
I've seen various solutions with using \b but I can't figure out where to put it in my code. Thanks.