'extract url and name attributes from the given string
the format of the input string is >>
[https://thisisurl.com] This is Name
how to extract "https://thisisurl.com", 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
Solution 1:[1]
You can use escape character \ for this as follow:
const str = '[https://thisisurl.com] 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}"`)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ashok |
