Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda