Regex to match binary numbers with more than two set bits -


if have number consisting of 1's , 0's , need create regular expression match if said number contains more 2 instances of digit 1.

some examples:

1000000010001 0001100000000 1000110010000 0000001000000 0100010000000 

i'd need expression correctly match 1st , 3th examples.

i'm guessing should basic stuff. best managed was:

1.+1.+(1) 

it's giving me problems though, i'd know if there's better way go this.

what did pretty good. changed little bit match complete number , accommodate possible cases:

((?:0*1){3,}0*) 

see example here.

this is, of course assuming have binary numbers. if not, feel free change 0 [02-9] include other digits, too.

breakdown

(?:0*1) matched number of 0 , 1 1. {3,} means find group @ least 3 times, means there have @ least three, i.e. more two, 1. match number of 0s in case number not end in 1 , include whole number in match.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -