Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript获取具有多个相同字符的子字符串_Javascript - Fatal编程技术网

Javascript获取具有多个相同字符的子字符串

Javascript获取具有多个相同字符的子字符串,javascript,Javascript,假设我有字符串: var post = "[PostContent(postId=123e4567-e89b-12d3-a456-426655440000, postName=My New House, picture=house.jpg, location=San Francisco)]" 我试图从postId中删除UUID,因此新生成的字符串只有以下值: 123e4567-e89b-12d3-a456-426655440000 谢谢你的帮助 更新: 很抱歉,我已经尝试了一个不完整的问题:

假设我有字符串:

var post = "[PostContent(postId=123e4567-e89b-12d3-a456-426655440000, postName=My New House, picture=house.jpg, location=San Francisco)]"
我试图从postId中删除UUID,因此新生成的字符串只有以下值:

123e4567-e89b-12d3-a456-426655440000
谢谢你的帮助

更新:

很抱歉,我已经尝试了一个不完整的问题:

var firstvariable = "postId=";
var secondvariable = ", postName=";
string.match(new RegExp(firstvariable + "(.*)" + secondvariable));

你可以使用这个方法

var post=“[PostContent(postId=123e4567-e89b-12d3-a456-426655440000,postName=My New House,picture=House.jpg,location=San Francisco)];
console.log(
post.match(/postId=([\w-]+)/)[1]

)
请共享您尝试过的代码。您尝试过什么吗?使用
postId=([\w-]+)
regex
string.substring(string.lastIndexOf("postId=")+1,string.lastIndexOf(", postName"));
var regex = /(.*postId=\s+)(.*)(\s+, postName.*)/;
var newtext = string.replace(regex, "$2");