Skip to content

Extract quoted string from a sentence in JavaScript

If you have a sentence like Hello “Good Morning!” and you want to extract the part inside the quotations you can use this solution.

Advertisements

You can match the sentence with regex /”(.*?)”/g. This regular expression finds the quotes and extracts the words inside the quotes.

console.log("Hello, \"Good Morning!\"".match(/"(.*?)"/g));

["Good Morning!"]

Regex match returns an array.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.