如何使用JavaScript Regex替换字符串中双引号之间的文本? [英] How to replace text between double quote in string using JavaScript Regex?

查看:54
本文介绍了如何使用JavaScript Regex替换字符串中双引号之间的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a JS string which contain text between double quotes ("). I want to replace that text by another user-entered text by using RegEx but I do not know how to do that. For example:

给出字符串:

The book "A Farewell to Arms" will be published again.

新文本:随风而去->上面的句子将是

New text: Gone with the Wind --> the above sentence will be

The book "Gone with the Wind" will be published again.

您能帮我解决这个问题吗?对不起这个问题,因为我是JS RegEx的新手.

Could you please help me to solve this case? Sorry for this dummy question because I am new to JS RegEx.

推荐答案

应该这样做.

str.replace(/".*?"/,"\"Gone with the Wind\"");

这篇关于如何使用JavaScript Regex替换字符串中双引号之间的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆