最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to replace “ &ldquo with double quotes? - Stack Overflow

programmeradmin8浏览0评论

I would like to do something like this:

 s = s.replace(/(”)/g, '"'); // need to replace with double quotes
 s = s.replace(/(“)/g, '"'); // need to replace with double quotes
 s = s.replace(/(’)/g, "'"); // need to replace with single quotes

But for me this does not work. I tried all the ways.

I would like to do something like this:

 s = s.replace(/(”)/g, '"'); // need to replace with double quotes
 s = s.replace(/(“)/g, '"'); // need to replace with double quotes
 s = s.replace(/(’)/g, "'"); // need to replace with single quotes

But for me this does not work. I tried all the ways.

Share Improve this question edited Sep 4, 2020 at 10:41 Flux 11k6 gold badges62 silver badges108 bronze badges asked Sep 24, 2012 at 22:57 niminimi 5,50718 gold badges62 silver badges90 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

You can use Unicode values in replace:

s = s.replace(/\u201C|\u201D/g, '"');  // for “ or ”
s = s.replace(/\u2019/g, "'");         // for ’

DEMO: http://jsfiddle/uM2fY/

So we open console, and see:

>>> 'test&rqduo;foo'.replace(/&rqduo;/g, '\"' );
test"foo

and with braces:

>>> 'test&rqduo;foo'.replace(/(&rqduo;)/g, '\"' );
test"foo

Everything work just like you thought. Please, check your input strings.

发布评论

评论列表(0)

  1. 暂无评论