regex
by bvotcode
JavaScript
var bad_json_string = `{'question_1':{ 'type':'string', 'title': 'There are some pretty life-changing inventions PREDICTED to come in the next century.', 'enum':['foreseen','forgotten','forgiven'],'requested':false},'question_2':{ 'type':'string', 'title': 'Regulations are still in the works, but in sounds like you'll be WHIZZING AROUND in your flying car well before 2120', 'enum':['moving very quickly','moving back and forth','moving out'],'requested':false},'question_3':{ 'type':'string', 'title': 'People are expecting that we'll be 3D printing incredible homes and even making them FOLDABLE and transportable.', 'enum':['capable of being folded up and stored','capable of being heard and smelled','capable of being stretched'],'requested':false},'question_4':{ 'type':'string', 'title': 'So it's already ON ITS WAY to beating Triangle Bob in an arm wrestling match!', 'enum':['approaching','affordable','available'],'requested':false},'question_5':{ 'type':'string', 'title': 'One of the most promising advancements in the field is having a mechanical "'"third arm' to HELP YOU OUT with tasks.', 'enum':['assist','abandon','accomodate','See how you did'],'requested':false}}`;
let depth = 0;
let cleaned_string = bad_json_string.replace(/[“”‘]|’(?!s)/g, m =>
"“‘".includes(m) ? "“‘"[depth++] : "”’"[--depth]);
document.write(bad_json_string);