Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java regular expression for binary string

Tags:

java

regex

First, I need to read a binary String from file into memory - how ? To read I tried nio.CharBuffer, and then byte[]. But later I need to get a binary String with all possible binary data to do regular expression on, so it was not a success.

Then, I need to extract binary sequences from this binary string and save them in each separate binary file. Regular expr is something like this "some_string \0{4} \2.+?\0{10}", some_string followed by a space, then the \2 byte, then binary data and then 10 NULL bytes.

What would you recommend?

like image 742
EugeneP Avatar asked Apr 09 '26 07:04

EugeneP


1 Answers

I'm not sure your using the right tool here, however,

  • make sure you are using a 1-byte encoding such as ISO-8859-1 to convert between String and byte[],
  • note that a '.' in a regexp excludes the end of line character, so you may want to use [\0..\255] instead
like image 66
Maurice Perry Avatar answered Apr 11 '26 20:04

Maurice Perry