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

114
Vistas
Match 10 digit alternating numbers

I want a regex which matches 10 digit alternating numbers like 1212121212 3434343434 so on. I know this is not right way to ask here. But I tried a lot from my side I was not able to figure out so reaching out for help.

It cannot be 1313131313. I should be the next number.

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

0

If the string is always 10 characters long and we always have single-digit numbers then simply take the first two characters, repeat 5 times and compare:

const check = str => {
  const a = +str[0];
  const b = +str[1];
  return a+1 === b && `${a}${b}`.repeat(5) === str;
};

check('1212121212');
//=> true

check('1212121215');
//=> false

check('1313131313');
//=> false
about 4 years ago · Juan Pablo Isaza Denunciar

0

You might also use Array.from and specify a length and an offset to get the alternation for the next number:

const alternating = (len, offset) =>
  Array.from({ length: len }, (_, index) => (index % 2) + offset).join('');

console.log(alternating(10, 1) === "1212121212");
console.log(alternating(10, 3) === "3434343434");
console.log(alternating(10, 2) === "1313131313");

about 4 years ago · Juan Pablo Isaza Denunciar

0

For pure regex you would just have to work out the different combinations because regex doesn't support the concept of numbers nor their sequence; everything is a string of chars.

^(01|12|23|34|45|56|67|78|89)\1{4}$

If 9090909090 is valid then:

^(01|12|23|34|45|56|67|78|89|90)\1{4}$
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