Sometimes, we want to get text between double quotes with JavaScript.
In this article, we’ll look at how to get text between double quotes with JavaScript.
How to get text between double quotes with JavaScript?
To get text between double quotes with JavaScript, we can use a regex.
For instance, we write:
const s = `"hello world"`
const [_, text] = s.match(/"((?:\.|[^"\])*)"/)
console.log(text)
to call s.match with /"((?:\.|[^"\])*)"/ to return an object with the text between the double quotes in the 2nd entry.
Therefore, text is 'hello world'.
Conclusion
To get text between double quotes with JavaScript, we can use a regex.