Skip to content

extract url and name attributes from the given string

the format of the input string is >>

[] This is Name

how to extract “”, and “This is url” attributes from it

where the url attribute is given in brackets [???] and remaining text is the name attribute

I want a function that can do this task for me


You can use escape character for this as follow:

const str = '[] This is Name'

const regex = /[(.*)] (.*)/i
const matchResult = str.match(regex)

const url = matchResult[1]
const name = matchResult[2]

console.log(`url: "${url}" name: "${name}"`)