1

I am trying to get information inside quotes in node.js

For example:

var information = 'Hello "beautiful and amazing" world.'

How can I log the content written inside the of the " "? I want to get this as result: beautiful and amazing

MegaMix_Craft
  • 2,199
  • 3
  • 10
  • 36

1 Answers1

3

Using regex:

var information = 'Hello "beautiful and amazing" world.'
var regex = /".+"/
var match = information.match(regex)
var res = match?.[0].slice(1, match[0].length - 1)
console.log("Result: " + res)

This checks for " then any text, then another ". Then it removes the "s

MrMythical
  • 8,908
  • 2
  • 17
  • 45