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

152
Visualizações
How would I get a discord tag from a string with regex?

I don't have basically any experience when it comes to regex, and have a basic understanding of string manipulation. I am trying to separate a discord tag from the rest of a string, but am running into issues.

For example, I was able to separate a tag like vunsh#3191 from 'vunsh#3191 has done blah blah blah`. But when a discord tag has a space in it or other characters, it doesn't detect it with the system I'm using right now.

Ex. My current system would get just vunsh's from vunsh's discord#1234 blah blah blah. I need vunsh's discord#1234

I found a method called string#match(), and it seems to be what I am looking for. What I am struggling with is what to put as the regex pattern that passes into #match().

Ex.

const paragraph = 'vunsh thing#2134 blah blah';
const regex = //what goes here?
const found = paragraph.match(regex);

console.log(found);
// expected output: Array ["vunsh thing#2134"]

Note: Not all the strings I am working with contain the word "vunsh", but all discord tags have a # and 4 numbers right after that.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You could use

const regex = /.*#\d{4}\b/g;

But this wont work in all cases where theres text before the username, for that there is no solution.

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