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

143
Vistas
Split a string and specify characters like , . :

I'm writing an assembler parser using JavaScript (don't ask why)
Need to split words, but characters like . , : need to be separate array element

As a solution i can use .split(' ') and just check with .includes(/[,|.|:]/g) find index and push after that element, but I think there is a better solution for this task.

Example

input: 'mov al, bl'
output: ['mov', 'al', ',', 'bl']
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use regular expressions in split() to include separator characters in final array.

let test = "mov al, bl"

let res = test.split(/([,\.:])/).map(el => el.trim().split(" ")).flat()
console.log(res)

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