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]$)
[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")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.