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

Regular Expression to get value from brackets and parenthesis followed by @

I need to get values from [] and () within string. I have below string and need to use Regex to extract username and Display Name from it.

let string = "this is string from @[username](Display Name). Thank you!"

string.match(/WAHT_REGEX??/g) to get username and Display Name

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

How do I write Regex to get username and Display Name from the string?

>Solution :

Try this one: '@\[([^\]]+)\]\(([^\)]+)\)'

Example on the Python language

import re
text = "this is string from @[username](Display Name). Thank you!"
re.findall('@\[([^\]]+)\]\(([^\)]+)\)', text)  #[('username', 'Display 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