I want to replace certain strings (roman numbers) in a string with nodejs.
A simple concatenation of .replace()
is not working as expected, because obviously some roman numbers are contained with other roman numbers. That sounds awful, but this example explains:
"III".replace('I', '1');
// "111";
offcourse we can reorder the .replace()
methods to surpress this behaviour, like so:
"III".replace('III', '3').replace('II', '2').replace('I', '1');
// "3"
But then with XI we get into trouble.
Is there a smarter way to do this?