I want to build a regex expression that allows me to parse through text files with thousands of lines, and each line contains one number with a variable size of digits.
Each number only can contain either the digits 1 or 0 (zero).
The requirement is there MUST be at least 3 1’s in the number, and at least one zero. Therefore, the minimum required size of each number is 4 and it has unlimited maximum.
For example, it has to match:
000000111 - has at least 1 zero and 3 ones
1110 - same thing
11111000 - same thing
111 - FAIL, because it's under 4 digits long
0000000011 - FAIL, needs at least 3 ones
Can anyone help me please? My problem is that I can’t determine how to find ‘at least 3 ones and one zero anywhere in the number’, key word being anywhere.
You could match such numbers with:
(?=1*0)make sure there is at least 10with a lookahead(?=...)(?:0*1){3}match the number with 31s[10]*match the rest or the number