regex - How to build a regular expression (C#) to identify a string of eight 1's & 0's -


i'm trying build regex determine if string contains byte of binary digits, ex. 10010011.

i believe [0-1][0-1][0-1][0-1][0-1][0-1][0-1][0-1] work, i'm sure theres more efficient way of doing it, , being new regular expressions, i'm not sure is.

if needs 8 (no more/less), use this:

@"(?<![01])([01]{8})(?![01])" 

if don't want match "abc01010101xyz", use this:

@"\b[01]{8}\b" 

if want match 8-bit strings anywhere in input, use this:

@"[01]{8}" 

be aware if feed last pattern input 1111111100000000, you're going result set like:

11111111 11111110 11111100 11111000 ... 00000000 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -