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

85
Views
Javascript question regarding the use of regex

I need to find a regex expression for a number 1 to 9, followed by trailing zeroes, followed by the end number 1 to 9. As like in a minesweeper game for clearing zeroes.

How do I match the part of an array where like i have 10009 or 2003 ? ,1to9 then zeroes, then 1to9? How would I write it?

does this work? updated: how do I ask this regex or another regex? the one i have below or a (trailing zeroes and 1-9)

(^[1-9][0+][1-9]$) 
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

[1-9][0]+[1-9]

Move the + outside of the square brackets. Otherwise, it will match the literal character.

const regex = new RegExp("[1-9][0]+[1-9]")

function test(testCase){
  console.log(regex.test(testCase))
}

test("10009")
test("2003")

To make the first digit optional, you can do:

[1-9]?[0]+[1-9]

const regex = new RegExp("[1-9]?[0]+[1-9]")

function test(testCase){
  console.log(regex.test(testCase))
}

test("0009")
test("2003")

about 4 years ago · Juan Pablo Isaza Report

0

When you say [0+] then you are saying that select any of either 0 or +

you want is quantifier 0+ which means 0 one or more times

You can use ^[1-9]0+[1-9]$

enter image description here

const regex = /^[1-9]0+[1-9]$/;

function test(str) {
  return regex.test(str);
}

console.log(test("10009"));
console.log(test("2003"));

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!