如何使用JavaScript Regex替换字符串中双引号之间的文本?

Đin*_*hâu 2 javascript regex

我有一个JS字符串,其中包含双引号(")之间的文本.我想通过使用RegEx用另一个用户输入的文本替换该文本,但我不知道该怎么做.例如:

给定字符串:

The book "A Farewell to Arms" will be published again.
Run Code Online (Sandbox Code Playgroud)

新文字:乱世佳人 - >上面的句子将是

The book "Gone with the Wind" will be published again.
Run Code Online (Sandbox Code Playgroud)

你能帮我解决这个案子吗?很抱歉这个虚拟问题,因为我是JS RegEx的新手.

Ani*_*dha 5

这应该这样做.让我为我的错字错误.我不是一个JavaScript开发

str.replace(/".*?"/,"\"Gone with the Wind\"");
Run Code Online (Sandbox Code Playgroud)

  • 你也可以使用`"[^"]*"`. (3认同)