Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
How to strip and convert this using regex

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!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Regardless of the language/platform, your RE pattern will have three parts:

  • mark the start of the string as a capture group: @[
  • match the middle of the string: Abdullah
  • mark the rest of the string as a capture group: ](61dfaceadef99a95503119a8)

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.

about 4 years ago · Juan Pablo Isaza Report

0

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 );

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!