Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
    
Do you have problems with creating the expression or applying it in JavaScript? The expression is not different that what you us in other languages. –  Felix Kling Aug 20 '12 at 15:56
add comment

1 Answer

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

str.replace(/".*?"/,"\"Gone with the Wind\"");
share|improve this answer
1  
You could also use "[^"]*". –  Felix Kling Aug 20 '12 at 15:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.