I am working on allowing users to make mentions and it's saved in the database this way @[Abdullah](61dfaceadef99a95503119a8) sometimes can be in a sentence or paragraph.
How can i make so that if a sentence or paragraph contains a mention it's converted?
From: hey @[Abdullah](61dfaceadef99a95503119a8) check this out and @[James](61dfaceadef99a95514562) welcome to the group!
To: hey Abdullah check this out and James welcome to the group!
Regardless of the language/platform, your RE pattern will have three parts:
Assuming you're just looking for the regex pattern in ECMAScript, you'll need something like:
(\@\[).*(\]\([a-f0-9]+\))
Run that through match() or matchAll() to identify matches, or use replace() on the matches. javascript.info has an example using capture groups - that looks close enough to your scenario.
I finally had time to get it done and came up with an answer also thanks to @Denton Thomas answer i was able to understand what to do.
let str = "hey @[Abdullah](61dfaceadef99a95503119a8) check this out and @[James](61dfaceadef99a95514562) welcome to the group!";
let regexp = /((.)\[([^[]*)]\(([^(^)]*)\))/gi
var result = str.replace(regexp, function(data){
console.log("data:", data)
let name = data.match(/([^[]+(?=]))/g)
console.log("name:", name)
return name[0]
});
console.log("message:", result );