0

I was looking at some custom code to read a binary file today and realized that surely this should be a job for a regular language, similar to regexs for matching, extracting data from text.

Is there anything like this? A fairly standard convention for notating a regular language to parse binary files? Particularly one which has implementations / wrappers in several programming languages?

1 Answer 1

1

Is there anything like this?

Yes. It is called - regexp. Binary files are simply strings with 8-bit "encoding".

However, binary files can be encrypted, or can have non-linear structure, in which case you need to read them using the tools applicable to the structure (just like you don't use regexps for, e.g. XML, JSON, or similar structured text strings).

Sign up to request clarification or add additional context in comments.

4 Comments

Yes. But traditional regex doesn't have ways to refer to bytes which aren't standard characters, does it?
Of course it does. Ruby: [65,66,1,0,69].pack('c*').match(/\x41B.\000\105/). Plenty of ways to refer to non-ASCII bytes.
Is that \x notation "standard" (as in the egrep / Perl standard)?
As far as I know, it is not POSIX standard (the only relevant standard beside the mathematical regular expressions), but I might be wrong. But Perl does also interpret them: "A\000C" =~ /\x41\000./. If you are interested in a particular regexp dialect, that should have been in your original question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.