none
Regex for binary data in string format. RRS feed

  • Question

  • Hi,

    I would like to have a regex pattern for below strings, my string length is always 10. Basically my string is having binary data with length 10.

    string temp1 = "0xxxxxxxxx"

    string temp2 = "10xxxxxxxx"

    string temp3 = "11xxxxxxxx"

    string temp4 = "1x00xxxxxx"

    string temp5 = "1x01xxxxxx"

    string temp6 = "1x10xxxxxx"

    string temp7 = "1x11xxxxxx"

    string temp8 = "1xxx000xxx"

    string temp9 = "1xxx001xxx"

    string temp10 = "1xxx010xxx"

    string temp11 = "1xxx011xxx"

    string temp12 = "1xxx100xxx"

    string temp13 = "1xxx101xxx"

    string temp14 = "1xxx110xxx"

    string temp15 = "1xxx111xxx"

    string temp16 = "1xxxxxx000"

    string temp17 = "1xxxxxx001"

    string temp18 = "1xxxxxx010"

    string temp19 = "1xxxxxx011"

    string temp20 = "1xxxxxx100"

    string temp21 = "1xxxxxx101"

    string temp22 = "1xxxxxx110"

    string temp23 = "1xxxxxx111"

    where x==> 0 or 1

    Your help is really appreciated.

    Thanks in advance,

    Hari


    click "Proposed As Answer by" if this post solves your problem or "Vote As Helpful" if a post has been useful to you Happy Programming! Hari

    Thursday, May 21, 2015 7:11 AM

Answers

  • For the first input, try: ^(?=(0|1){10})0.........$, for the second: ^(?=(0|1){10})10........$, etc. For each case just adjust the part between “)” and "$".

    You can also parse and convert to number (using Convert.ToInt32), then analise the number using a switch or if.


    Thursday, May 21, 2015 7:38 AM

All replies

  • Seems that your 23 examples cover all of the possible 10-digit values. Therefore try this expression:

        ^(0|1){10}$

    Thursday, May 21, 2015 7:18 AM
  • Hi,

    Thanks for the reply,

    Basically i want specific pattern for each input. So i want 23 patterns.

    Thanks and Regards,

    Hari


    click "Proposed As Answer by" if this post solves your problem or "Vote As Helpful" if a post has been useful to you Happy Programming! Hari

    Thursday, May 21, 2015 7:26 AM
  • For the first input, try: ^(?=(0|1){10})0.........$, for the second: ^(?=(0|1){10})10........$, etc. For each case just adjust the part between “)” and "$".

    You can also parse and convert to number (using Convert.ToInt32), then analise the number using a switch or if.


    Thursday, May 21, 2015 7:38 AM
  • Hi,

    Thanks for the reply.

    You can also parse and convert to number (using Convert.ToInt32), then analise the number using a switchor if.

    As you said above, what i need to parse? I didn't understand what you said. Can you elaborate pls?

    Thanks a lot,

    Hari


    click "Proposed As Answer by" if this post solves your problem or "Vote As Helpful" if a post has been useful to you Happy Programming! Hari

    Thursday, May 21, 2015 10:04 AM
  • Hi Hari,

    >>As you said above, what i need to parse? I didn't understand what you said. Can you elaborate pls?

    What i understand is that Viorel you could parse your input string as "1x000000"convert to number. And the solution Viorel already provided a workaround.

    Friday, May 22, 2015 8:41 AM
  • Hi Viorel,

    Thanks a lot, its work great.

    Thanks and Regards,

    Hari


    click "Proposed As Answer by" if this post solves your problem or "Vote As Helpful" if a post has been useful to you Happy Programming! Hari

    Tuesday, May 26, 2015 4:06 AM