Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 :

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}"`)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading