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

179
Visualizações
How do I separate tags in a string

I am currently using .split to try to split a string into different 'tags'.

let text = "@yusra is cool @zain @chris is cool";
const myArray = text.split("@");
console.log(myArray);

The code above gives this output:

Array ["", "yusra is cool ", "zain ", "chris is cool"]

the expected output is:

Array ["yusra", "zain ", "chris"]

How do I modify this to make it do what I want.

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

0

You could try something like this:

let text = "@yusra is cool @zain @chris is cool";
const myArray = text.split(" ").filter(s => s.startsWith("@")).map(s => s.substring(1));
console.log(myArray);

about 4 years ago · Juan Pablo Isaza Relatório

0

Instead of using split you can use match to find the tags via a regex.

let text = "@yusra is cool @zain @chris is cool";
const myArray = text.match(/@\w+/g);
console.log(myArray);

about 4 years ago · Juan Pablo Isaza Relatório

0

Use match with a regex. Here we match @ and then one or more lowercase letters between "a" and "z".

const text = "@yusra is cool @zain @chris is cool @bob";
console.log(text.match(/@[a-z]+/g));

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