Good day Monks,

I'm having some difficulty searching binary data with regular expressions. The problem appears to be due to a numerical 10 within my data that is being interpreted as a line feed.

Is there any way to indicate to the regex to ignore line feeds (similar to using $\=undef for files) or any other suggestions on how to get the desired results?


The following code demonstrates the problem. Whenever I am looking for "any characters" using .{x} and the span includes a 10, it will fail to find it.

my $data = "\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11"; my @find = ( # These Work "\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11", "\x04\x05.{4}\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11", "\x04\x05\x06\x07\x08.{1}\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11", "\x04\x05\x06\x07\x08\x09\x0a.{1}\x0c\x0d\x0e\x0f\x10\x11", #These don't work "\x04\x05.{5}\x0b\x0c\x0d\x0e\x0f\x10\x11", "\x04\x05\x06\x07\x08\x09.{1}\x0b\x0c\x0d\x0e\x0f\x10\x11" ); foreach (@find) { if ($data =~ /$_/) { print "found\n" } else { print "not found\n" } +; };
Running the code will output:
found
found
found
found
not found
not found


Also, does anyone know a good online regexp reference? I had an excellent reference at http://japhy.perlmonk.org/book/ bookmarked, but it looks like it has been removed.

Thanks

In reply to Using regexp with binary data by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.