Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

221
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda