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

Remove text between first and last brakets

My original string :

[Abc ![](https://i.imgur.com/5AteeJf.png)](https://quiz.com?/quiz_id=2/quiz_name=15/level=null)

i tried with this javascript formula but no luck

string.replace(/ *\[[^\]]*]/, '') 

How can i remove string between first [ and last ]?

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

Thank you so much

My desired output is url

https://quiz.com?/quiz_id=2/quiz_name=15/level=null

>Solution :

Just use .* instead of [^\]]*, so the match won’t stop at the first ].

let string = '[Abc ![](https://i.imgur.com/5AteeJf.png)](https://quiz.com?/quiz_id=2/quiz_name=15/level=null)';
let result = string.replace(/\[.*\]/, '');
console.log(result);
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