Regex Match range numbers between 13000 to 99999 - regex

I am trying to write some form validation, I need one of the inputs to be 13000-99999.
(^[1-1][3-3]?[0-9]?[0-9]?[0-9]?$|^[0-9][0-9][0-9][0-9][0-9]$)
It does not work as expected and it match all the following :
10 \\ matched but it should not
10000 \\ matched but it should not
12999
13000
20000
99999
can anyone help me? Thanks!

Although the way you are doing this is not ideal. But if you are doing with this approach, your regex needs some changes:
(^[1-1][3-9][0-9][0-9][0-9]$|^[2-9][0-9][0-9][0-9][0-9]$)
This is because if the 1st digit is a 1, then the second number should be between a 3 and a 9. If the 2nd digit is a 2, then any of 0-9 is valid for the second digit. The last three digits are always 0-9 range.

You have more than one issue here
(^[1-1][3-3]?[0-9]?[0-9]?[0-9]?$|^[0-9][0-9][0-9][0-9][0-9]$)
1 - You have to remove all question mark ?
2 - In the second pattern in the first part [3-3] should be from [3-9]
3 - In the second part after | this should be from [2-9]
You can use one of the following regex (^[1-1][3-9][0-9][0-9][0-9]$|^[2-9][0-9][0-9][0-9][0-9]$), (^[1-1][3-9]|^[2-9][0-9])[0-9][0-9][0-9]$ or 1[3-9]\d{3}|[2-9]\d{4}
first you need to match any number that start from 1 and from 3 to 9 or start from 2 to 9 and any number 0 to 9 and all rest number can any from 0 to 9

Related

regex expression in javascript

I am trying to build a regex in javascript to match a 9-digit number with these characteristics:
First 3 digits should not be ‘0’ ,
4th and 5th Digit should not be ‘0’,
Last 4 digits should not be ‘0000’,
First 3 digits should not be ‘666’,
Last 3 Digits Should not be greater than ‘899’
Can someone please help me out with this.
Here is my current regex:
/^666[^0]{3}[1-9]{2}0000$/
, but it’s not meeting the criteria
Try This regular expression it will work ^(?!(000)|(666))[0-9]{3}[1-9]{2}[0-9][0-8][0-9]{2}(?<!0000)$. See demo here
Try this ^[^06]{3}[^0]{2}[^0][1-8][^0]{2}$
Below is my explanation for it
First 3 digits should not be ‘0’
First 3 digits should not be ‘666’,-> ^[^06]{3}
4th and 5th Digit should not be ‘0’, -> [^0]{2}
Last 4 digits should not be ‘0000’, -> [^0]{4}
Last 3 Digits Should not be greater than ‘899’ -> [1-8][^0]{2}$
Because all nine characters need to be a digit, you might use lookahead from the beginning to check that there are 9 digits followed by the end of the string, which will make the subsequent groups easier to manage. Then, you need to utilize character sets and negative lookahead. The first two conditions look to collapse together - the first five characters need to be other than 0:
/^(?=\d{9}$)(?!666)[^0]{5}(?!0000)\d[^9]/
const re = /^(?=\d{9}$)(?!666)[^0]{5}(?!0000).[^9]/;
`555555555
5555555555
055555555
555505555
666555555
555550000
555550001
555550900
555550953`
.split('\n')
.forEach(n => console.log(re.test(String(n))));
Explanation:
555555555 true
5555555555 false; 10 digits, not 9
055555555 false: has 0 in first 5 digits
555505555 false: has 0 in first 5 digits
666555555 false: starts with 666
555550000 false: ends with 0000
555550001 true
555550900 false: sixth digit is a 9 (so last 3 digits are 9xx, which is greater than 899)
555550953 false: same as above
https://regex101.com/r/Vpwbk0/1

RegEx: How can I match optional comma separated integers between 5 to 100?

I'm trying to match a comma separated string that can be empty. The following strings would pass:
""
"12"
"5,100"
"5,34,55,12"
"5,8,15,9,94"
The following would fail:
"2" - Because 2 is less than 5
"4,15" - Because 4 is less than 5
"87, 3" - Because 3 is less than 5
"39,7,23,62, 1" - Because 1 is less than 5
"25," - Because no number comes after the comma
Currently I have the the following regex: ^(\d+(,\d+)*)?$ which is able to match comma separated integers. What I'm not able to do is matching that all the integers are between 5 and 100.
Regex: ^((?:[5-9]|([1-9][0-9])|100)(,(?:[5-9]|([1-9][0-9])|100))*)?$ should check numbers between 5 - 100.
Demo
I was able to solve it using this regex:
^(([5-9]|[1-9][0-9]|100)(,([5-9]|[1-9][0-9]|100))*)?$
Breakdown:
^ marks the start.
$ marks the end of the string.
? makes the string optional i.e. one or zero occurrences of the string.
([5-9]|[1-9][0-9]|100) matches numbers 5 - 9 or 10 to 99 or 100 respectively.
(,([5-9]|[1-9][0-9]|100))* means that there can be zero or more occurrences of a comma followed by a number between 5 - 100.
This regex ^(?!.*(?:\b[1-4]\b|^\s*,|,\s*,|,\s*$)).*$ must exclude strings containing numbers 1, 2, 3, or 4.

regex to match any number which is greater than 5

I need to match fail counts greater than 5.
string="""fail_count 7
fail_count 8
fail_count 9
fail count 7
fail_count 71
fail_count 23
"""
match = re.search(r'fail(\s|\_)count\s[5-9]', string)
if match:
print match.group()
I am able to match up to 9, but if I increase the range to 999 it doesn't work.
5-9 or at least 2 digits
'([5-9]|\d{2,})'
or to match the whole numbre when it starts by 5-9.
5-9 followed by any number of digits or at least 2 digits
'([5-9]\d*|\d{2,})'
Maybe this regex solution can help
fail(\s|\_)count\s([0-9]{2,}|[5-9]{1})
see on regex101

Regex, numbers below 20k

I'm looking for a regex to validate if numbers are below 20 000.
I can't find the right solution, I have so far this:
(^([1-9]([0-9]{0,3})|20000)$)
Which works quite ok but as soon as it gets to 10 000 it gives no matches. So I have a gap from 9 999 - 20 000.
What am I doing wrong? I don't use regex for these situations, but the 3th party program required regex for such..
Thanks!
Your regex - ^([1-9]([0-9]{0,3})|20000)$ - matches numbers from 1 till 9999 and 20000.
You may use
^([1-9]\d{0,3}|1\d{4}|20000)$
See demo
Breakdown:
^ - match start of string
([1-9]\d{0,3}|1\d{4}|20000) - match one of the alternatives:
[1-9]\d{0,3} - 1 to 9 followed with 0 to 3 any digits (from 1 till 9999)
1\d{4} - 1 followed with any 4 digits (to match 10000 - 19999)
20000 - literally 20000
$ - match the end of string
I've got this:
^([01]?\d{0,4}|20000)$
Which match any number from 0 to 20 000 and allow the user to use number with leading 0 Live Demo
The ([1-9]([0-9]{0,3}) part is designed to match all numbers strictly below 2000 but you define it as: "A digit one to nine followed by zero to three digits". Now 10 000 is a one followed by four zeros: you can rewrite the part as:
[1-9][0-9]{3}|1[0-9]{4}
The full regex is now:
^[1-9][0-9]{3}|1[0-9]{4}|20000$

Regex not working as expcted

I need help with the below regex:
(0 ?)([1-8] ?){1}(\d ?){9}|(\d ?){10}
The regex should match either 10 or 11 digits
The first digit should be 0
The second digit should contain from 1 - 8 digits only
All digits can have spaces in between e.g. 0 1 2 7 4 3 3 3 4 4 4
Digits can be without spaces e.g. 01274333444
The regex I created works for most of the scenarios apart from the third condition i.e. The second digit should contain from 1 - 8 digits only.
Any help very much appreciated
Here is what your regex (0 ?)([1-8] ?){1}(\d ?){9}|(\d ?){10} is currently doing:
It's also trying to match 11 or 12 digits instead of 10 or 11.
What you need to do is change it one of the following ways:
Add a group around the OR | to limit it's scope: (0 ?)([1-8] ?){1}(?:(\d ?){8}|(\d ?){9})
Or preferably change it to a 8 or 9 character match: (0 ?)([1-8] ?){1}(\d ?){8,9}
You can use this:
^0 ?[1-8] ?(?:[0-9] ?){8,9}$
I used anchors ^ and $ to ensure that there is no leading or trailing digits.
Try this one:
^(0\s?)([1-8]\s?)(\d\s?){8,9}$