Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!