Reputation: 73
How can i replace quotes (""
) in text with guillemets («
and »
)?
I tried the usual method (replace with regexp) for replacing, but it turned out badly - I do not know how to determine if an opening quote or a closing quote.
Upvotes: 2
Views: 296
Reputation: 29277
You can do replace
with a regex - /"(.*?)"/g
to replace the whole "word".
console.log(
'"word1" word2 "word3"'.replace(/"(.*?)"/g, '«$1»'))
Or
console.log(
'"word1" word2 "word3"'.replace(/"(.*?)"/g, (a, b) => `«${b}»`));
https://regex101.com/r/9s68XL/1
Upvotes: 5