0

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

2
  • do you want to use API in javascript? or what do you mean by your question? Commented Mar 31, 2022 at 16:14
  • @AbdelhamedAbdin the question is simple, given a input string in format [1???] 2???, first value is given in bracket and remaining out of the bracket is second value, parse this string and fetch both values Commented Mar 31, 2022 at 16:16

1 Answer 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}"`)

Sign up to request clarification or add additional context in comments.

1 Comment

Indeed this is the right answer, though I already figured it out few minutes ago.. but thanks for help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.