I have a string in the form of:
"Hello, this is a test. Let's tag @[William Maness], and then tag @[Another name], along with @[More Name]."
I want to convert that to…
"Hello, this is a test. Let's tag <a href='/search/william-maness'>William Maness</a>, and then tag <a href='/search/another-name'>Another name</a>, along with [...]"
I’m fairly sure this can be done with regex, but it’s just a bit too complex for me to work out. Any help is appreciated.
re.sub()accepts functions as well, so you can process the replacement text:Or, if you’re looking for a readable one-liner: