0

I have a string as below

string = "my name is [name] and Birtday is [birthday]"

I want to get all the words inside the placeholders into an array. The following shows the array.

array = [ "name", "birthday" ]

I have the following code.

array = sting.match(/[^[\]]+(?=])/g)

But This also returns the below text as two arrays.

string = "[name]month]"
array = ["name", "month"] this should be array = ["name"]
Dmap
  • 129
  • 2
  • 17

0 Answers0