I am working with regular expressions for a class and we need to have it set up to contain at least 3 0 throughout the string. BUT they don't need to be next to each other, so 101010 would pass but 101011 would fail because it lacks a 0. ^[0-1]*(?:0){3,}[0-1]*$
This is what I currently have but that requires them to be adjacent.
How about:
([01]*0[01]*){3}
The 0 in the center without a qualifier ensures that it exists at least 3 times in your string. The [01]* on either side requires a 0 or 1 zero to unlimited times, giving it some wiggle room so as not to require that the 3 zeros occur consecutively. (Demo) (regexr.com)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments