Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace text between double quote in string using JavaScript 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:

Given string:

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.

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

like image 406
Đinh Hồng Châu Avatar asked Aug 20 '12 15:08

Đinh Hồng Châu


Video Answer


1 Answers

This should do it..Spare me for my typo mistakes.I am not a javascript dev

str.replace(/".*?"/,"\"Gone with the Wind\"");
like image 93
Anirudha Avatar answered Sep 28 '22 07:09

Anirudha