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
Related
I have the following regex which is matching the first 2 letters RR and then 4 numbers after.
RR[0-9]{4}
How can I change it to detect the first 2 letters RR and then up to 10 digits afterwards?
I know I can do...
^[0-9]*$
To match all numbers but how can I limit this and add it to the first regex?
You can use RR\d{0,10}. This matches RR, followed by 0 to 10 digits, i.e. up to 10 digits.
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
How I can write a regex which accepts 10 or 14 digits separated by a single space in groups of 1,2 or 3 digits?
examples:
123 45 6 789 1 is valid
1234 567 8 9 1 is not valid (group of 4 digits)
123 45 6 789 109 123 8374 is not valid (not 10 or 14 digits)
EDIT
This is what I have tried so far
[0-9 ]{10,14}+
But it validates also 11,12,13 numbers, and doesn't check for group of numbers
You may use this regex with lookahead assertion:
^(?=(?:\d ?){10}(?:(?:\d ?){4})?$)\d{1,3}(?: \d{1,3})+$
RegEx Demo
Here (?=...) is lookahead assertion that enforces presence of 10 or 14 digits in input.
\d{1,3}(?: \d{1,3})+ matches input with 1 to 3 digits separated by space with no space allowed at start or end.
aggtr,
You can match your use case with the following:
^(?:\d\s?){10}$|^(?:\d\s?){14}$
^ means the beginning of the string and $ means the end of the string.
(?:...) means a non-capturing group. Thus, the part before the | means a string that starts and has a non-capturing group of a decimal followed by an optional space that has exactly 10 items followed by the end of the string. By putting the | you allow for either 10 or 14 of your pattern.
Edit I missed the part of your requirement to have the digits grouped by 1, 2, or 3 digits.
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
I need help with a regex
I need it to match either a 9 or 10 digit value that starts with 50.
I have:
^[ ]*(50)[0-9]{7}[ ]*$
which allows 9 digits.
How can I expand this so that it also allows 10 digits?
Add the range {7,8}
^[ ]*(50)[0-9]{7,8}[ ]*$
FYI this site describes the standard quantifiers that you can use in a regular expression:
* Match 0 or more times
+ Match 1 or more times
? Match 1 or 0 times
{n} Match exactly n times
{n,} Match at least n times
{n,m} Match at least n but not more than m times
Try with following regex:
^[ ]*50\d{7,8}[ ]*$
This regex will match what you need:
^\s*50\d{7,8}\s*$
This will match all 9 or 10 digit numbers starting with 50 with an unlimited number of spaces before, or after, them on the line.
If you want to match all 9 or 10 digit numbers starting with 50 regardless of position and number of spaces etc then:
50\d{7,8}
will do exactly what you need.
Here's what you need: (50)\d{7,8}