收藏本站腾讯微博新浪微博

经典论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

蓝色理想 最新研发动态 网站开通淘帖功能 - 蓝色理想插件 论坛内容导读一页看论坛 - 给官方提建议

论坛活动及任务 地图和邮件任务 请多用悬赏提问 热夏来袭,选一款蓝色理想的个性T恤吧!

手机上论坛,使用APP获得更好体验 急需前端攻城狮,获得内部推荐机会 论坛开通淘帖功能,收藏终于可以分类了!

搜索
查看: 16375|回复: 5

求一个去除字符串中双引号的正则表达式

[复制链接]
发表于 2012-4-27 11:01:17 | 显示全部楼层 |阅读模式
本帖最后由 FishStanding 于 2012-4-27 13:43 编辑

如一个字符串中可能会出现双引号,位置不固定(可能在开头、中间、结尾)如:
var str = "\"蓝色理想\"里高手真多啊,谁帮忙解决这个问题?";
var str = "蓝色理想里高手真多啊,谁帮忙解决这个\"问题\"";
var str = "蓝色理想里\"高手\"真多啊,谁帮忙解决这个问题?";

甚至不排除会有多个的可能:
var str = "\"蓝色理想\"里\"高手\"真多啊,谁帮忙解决这个问题?";

希望能够去除之后得到的是原字符串:
"蓝色理想里高手真多啊,谁帮忙解决这个问题?";(能用相应的中文双引号更佳: "“蓝色理想”里高手真多啊,谁帮忙解决这个问题?";)

请达人们帮帮忙,看看如何解决?

谢谢两位的解答,我问题没有描述清楚,是这样的,我们引用了一个外部文件,返回值是一个字符串,但里面的内容是JSON格式的数据,Value值中可能会包含英文双引,现需要把这些英文双引号去除。

返回数据如下:
  1. var json = '[{"id":"2664864","catid":"138","title":"\u5370\u77f3\u6cb9\u516c\u53f8\u79f0\"\u4e0d\u4f1a\u56e0\u4e2d\u56fd\u6297\u8bae\u9000\u51fa\u5357\u6d77\u77f3\u6cb9\u5f00\u91c7\"","url":"http:\/\/world.huanqiu.com\/exclusive\/2012-04\/2664864.html","inputtime":"1335292800","updatetime":"1335312539","total":"808","count":"2272"},{"id":"2664891","catid":"135","title":"\u6881\u5149\u70c8\u5c31\u4e2d\u83f2\u5bf9\u5cd9\u8868\u6001\uff1a\u519b\u65b9\u884c\u52a8\u6839\u636e\u5916\u4ea4\u9700\u8981","url":"http:\/\/world.huanqiu.com\/roll\/2012-04\/2664891.html","inputtime":"1335295500","updatetime":"1335295646","total":"630","count":"1580"},{"id":"2665328","catid":"135","title":"\u4e2d\u56fd\u6e14\u8239\u5728\u4e2d\u65e5\u97e9\u4e09\u56fd\u95f4\u6d77\u57df\u6551\u8d7710\u540d\u9047\u9669\u97e9\u6e14\u6c11","url":"http:\/\/world.huanqiu.com\/roll\/2012-04\/2665328.html","inputtime":"1335315660","updatetime":"1335317638","total":"542","count":"971"},{"id":"2667193","catid":"135","title":"\u83f2\u5c06\u5728\u5357\u6c99\u4e2d\u4e1a\u5c9b\u5f00\u8bbe\u5c0f\u5b66 \u79f0\u4e2d\u65b9\u5173\u5207\u201c\u65e0\u7406\u7531\u201d","url":"http:\/\/world.huanqiu.com\/roll\/2012-04\/2667193.html","inputtime":"1335361260","updatetime":"1335361537","total":"442","count":"1281"},{"id":"2667209","catid":"134","title":"\u83f2\u5f8b\u5bbe\u5bf9\u9ec4\u5ca9\u5c9b\u95ee\u9898\u4e00\u518d\u6311\u8845 \u201c\u631f\u6d0b\u81ea\u91cd\u201d\u96be\u5f97\u901e","url":"http:\/\/world.huanqiu.com\/hot\/2012-04\/2667209.html","inputtime":"1335363784","updatetime":"1335363790","total":"423","count":"1011"},{"id":"2667326","catid":"135","title":"\u7f8e\u83f2\u519b\u4eba\u6f14\u4e60\u201c\u593a\u5c9b\u201d\u6218 \u4e13\u5bb6\u79f0\u4e2d\u65b9\u64a4\u8239\u4e0d\u662f\u8f6f\u5f31","url":"http:\/\/world.huanqiu.com\/roll\/2012-04\/2667326.html","inputtime":"1335389340","updatetime":"1335399943","total":"238","count":"657"},{"id":"2667328","catid":"135","title":"\u5916\u5a92\u5173\u6ce8\u6d77\u5357 \u518d\u63d0\u897f\u6c99\u65c5\u6e38","url":"http:\/\/world.huanqiu.com\/roll\/2012-04\/2667328.html","inputtime":"1335389640","updatetime":"1335389763","total":"232","count":"529"},{"id":"2670285","catid":"138","title":"\u65e5\u7f51\u6c11\u547c\u5401\u201c\u4e00\u4eba\u6350\u4e00\u4e07\u201d\u8d2d\u4e70\u9493\u9c7c\u5c9b","url":"http:\/\/world.huanqiu.com\/exclusive\/2012-04\/2670285.html","inputtime":"1335472680","updatetime":"1335472798","total":"197","count":"646"},{"id":"2670598","catid":"135","title":"\u5b66\u8005\u8b66\u544a\uff1a\u83f2\u6311\u8d77\u6218\u4e89 \u4e2d\u56fd\u5fc5\u6b66\u529b\u53cd\u51fb\u593a\u9ec4\u5ca9\u5c9b","url":"http:\/\/world.huanqiu.com\/roll\/2012-04\/2670598.html","inputtime":"1335486720","updatetime":"1335487820","total":"187","count":"333"},{"id":"2670646","catid":"135","title":"\u56fd\u9632\u90e8\uff1a\u4e2d\u56fd\u519b\u961f\u5c06\u5bc6\u5207\u914d\u5408\u6e14\u653f\u6d77\u76d1\u7ef4\u62a4\u6d77\u6d0b\u6743\u76ca","url":"http:\/\/world.huanqiu.com\/roll\/2012-04\/2670646.html","inputtime":"1335487380","updatetime":"1335504770","total":"163","count":"398"}]';
复制代码
 楼主| 发表于 2012-4-27 11:16:38 | 显示全部楼层
有高手在么,别潜水了~~
回复 支持 反对

使用道具 举报

发表于 2012-4-27 11:29:15 | 显示全部楼层

 提示:您可以先修改部分代码再运行

回复 支持 反对

使用道具 举报

发表于 2012-4-27 11:29:17 | 显示全部楼层

 提示:您可以先修改部分代码再运行

回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-4-27 13:54:47 | 显示全部楼层
另外再说明一点,变量直接写在页面里,转成JSON数据的格式去遍历是没有问题的,引用外部文件的时候才会出问题。

 提示:您可以先修改部分代码再运行

回复 支持 反对

使用道具 举报

发表于 2012-4-27 14:40:51 | 显示全部楼层
LZ你的问题还是没有描述清楚。。。。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|Archiver|手机版|blueidea.com ( 湘ICP备12001430号 )  

GMT+8, 2020-9-22 16:32 , Processed in 0.109100 second(s), 8 queries , Gzip On, Memcache On.

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表