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

128
Vistas
split with regexr with no empty elements

I want output be like this:
['YY','RR'] with no empty elements

function pntSq(m){
    let a = m.split(/([A-Z][A-Z])/gi)
    console.log(a)
}
pntSq("YYRR")
//    output :
//    [ '', 'YY', '', 'RR', '' ]

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You can match instead of using split.

function pntSq(m){
  return m.match(/[A-Z]{2}/g);
}

console.log(pntSq('YYRR'));

about 4 years ago · Juan Pablo Isaza Denunciar

0

Link: regex101

This matches any 2 uppercase letters together, but note that they may be different.

[A-Z]{2}

To match the same uppercase letter 2 times. This ensures that it's the same letter repeated and not different letters.

([A-Z])\1
about 4 years ago · Juan Pablo Isaza Denunciar

0

JavaScript may not support splitting on lookbehinds. One workaround would be to do this in two steps. First we can replace on the following regex pattern:

([A-Z])(?!\1)(?=.)

This will capture any capital which in turn is followed by a different letter (and also not the end of the string). Then, we replace with a single space. As the second step, we simply split on space to get the output array we want.

function pntSq(m) {
    m = m.replace(/([A-Z])(?!\1)(?=.)/g, "$1 ");
    console.log(m);
    var a = m.split(/ /g);
    console.log(a);
}

pntSq("YYRRAAABBBBBCC");

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