I know that I can use regex to match substrings in a string, but is it possible to match some patterns in binary data using regex? If so then in what format should the binary data be – binary array, stream, or something else?
edit:
well to explain i have binary data that shouldnt have some strings inside but the data itself is binary so i need to detect this pattern of data so i mark this data as invalid.
but i couldnt convert this binary data to string since it would be invalid. maybe only to some char[] or something.
edit:
now i am thinking maybe converting the binary data to a basic encoding (any hints on which is the most basic encoding available? certainly not unicode, i think ascii?) and then i will use regex.
but the question would i be able to convert any binary data to string using this encoding or i will encounter some cases which will be invalid and will cause exceptions when converting the binary data to string.
The technical answer to your question is yes, since you could just treat the binary data as a string of a particular encoding, but I don’t believe that’s what you’re asking.
If you’re asking if there’s a library designed to do pattern matching on an array of bytes, then the .NET regex system will not do this and there isn’t such a library that I’m aware of.