我有一个这样的字符串:
var examplestring = 'Person said "How are you doing?" ';
如何获取双引号内的字符串。具体来说,我想要一个设置为你好吗?在这种情况下。
我有一个这样的字符串:
var examplestring = 'Person said "How are you doing?" ';
如何获取双引号内的字符串。具体来说,我想要一个设置为你好吗?在这种情况下。
一种方法是使用正则表达式:
var match = exampleString.match(/"([^"]*)"/);
if(match) {
var quoted = match[1]; // -> How are you doing?
} else {
//no matches found
}
var quotedString = examplestring.split('"')[1];
这将在每个“,分成以下
quotedString[0] = "Person said ";
quotedString[1] = "How are you doing?"
quotedString[2] = " ";
然后从新数组的索引 1 中选择,返回“你好吗?” (不带引号)。
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/split
var examplestring = 'Person said "How are you doing?" ';
var extract = examplestring.match(/\"(.*)\"/);
alert(extract[1]);