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
  • 1,853
  • 2
  • 6
  • 26

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
  • 7,595
  • 2
  • 12
  • 40