marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
3.01k stars 793 forks source link

09_2_quoting_style.js - alternative regex #464

Closed zapalagrzegorz closed 5 years ago

zapalagrzegorz commented 5 years ago

At present proposed solution for 09_2_quoting_style.js is let text2 = "'I'm the cook,' he said, 'it's my job.'"; // Change this call. console.log(text.replace(/(^|\W)'|'(\W|$)/g, '$1"$2'));

I stumbled accross this one: console.log(text.replace(/\B\'/g, "\""));

which, also gives the same result. Is it reasonable?

marijnh commented 5 years ago

Seems to work. I didn't even know \B was a thing, but apparently it is!