我有一个 JS 字符串,其中包含双引号 ("
) 之间的文本。我想使用 RegEx 将该文本替换为另一个用户输入的文本,但我不知道该怎么做。例如:
给定字符串:
The book "A Farewell to Arms" will be published again.
新文本:乱世佳人-->上面的句子会是
The book "Gone with the Wind" will be published again.
你能帮我解决这个问题吗?很抱歉这个虚拟问题,因为我是 JS RegEx 的新手。
最佳答案
这应该可以做到。请原谅我的打字错误。我不是 javascript 开发人员
str.replace(/".*?"/,"\"Gone with the Wind\"");
关于javascript - 如何使用 JavaScript Regex 替换字符串中双引号之间的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12040833/