marijnh / Eloquent-JavaScript

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

Ch. 9 - Quoting style string #454

Closed tomkenny closed 6 years ago

tomkenny commented 6 years ago

If I'm not mistaken the regex for the current string only needs to be:

console.log(text.replace(/(^|\W)'/g, '$1"'));

For the extra regex that is indicated to be required I think the end period needs to be outside the quotations, such as:

let text = "'I'm the cook,' he said, 'it's my job'."

marijnh commented 6 years ago

Yes, for this particular example your regexp would also work, but the exercise asks for a regexp that matches all quotes except those in contractions.