在Javascript / JQuery中删除第一组引号之外的任何内容

时间:2016-01-07 19:55:09

标签: javascript jquery regex

我不想删除此字符串中第一组引号之外的任何字符:

toastr.warning("Cynthia Open Chat and respond to request","",{"timeOut":5000,"progressBar":true,})

结果是Cynthia G. Open Chat and respond to request

我正在使用类似/\w.*(?="\w){1}/之类的东西,但这似乎不起作用。

2 个答案:

答案 0 :(得分:0)

更易于使用match

var str = 'toastr.warning("Cynthia Open Chat and respond to request","",{"timeOut":5000,"progressBar":true,})';

var repl = str.match(/"[^"]*/)[0].substring(1);
//=> Cynthia Open Chat and respond to request

答案 1 :(得分:0)

尝试使用此RegExp

var str = 'toastr.warning("Cynthia Open Chat and respond to request","",{"timeOut":5000,"progressBar":true,})';

var text = str.replace(/^[^"]*?"([^"]+)".*$/, "$1");
// Cynthia Open Chat and respond to request