Home > Blockchain >  Regular Expression to get value from brackets and parenthesis led by @
Regular Expression to get value from brackets and parenthesis led by @

Time:02-02

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(/WHAT_REGEX??/g) to get username and Display Name

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

CodePudding user response:

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')]
  •  Tags:  
  • Related