in reply to Using regexp with binary data
The solution to the first of these problems is to use the s modifier on your regexp, as has already been mentioned. Note that you can encode this modifier into the regexp when you define it:
The solution to the second problem is to use \Z instead of $ when you absolutely need the very end of the string, even if it ends in a newline.my $data = "\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11"; my @find = ( # These Work qr"\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11"s, qr"\x04\x05.{4}\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11"s, qr"\x04\x05\x06\x07\x08.{1}\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11"s, qr"\x04\x05\x06\x07\x08\x09\x0a.{1}\x0c\x0d\x0e\x0f\x10\x11"s, #These didn't work before, but do now. qr"\x04\x05.{5}\x0b\x0c\x0d\x0e\x0f\x10\x11"s, qr"\x04\x05\x06\x07\x08\x09.{1}\x0b\x0c\x0d\x0e\x0f\x10\x11"s, ); foreach (@find) { if ($data =~ /$_/) { print "found\n" } else { print "not found\n" } +; };
As for online regexp references, doing perldoc perlre as suggested before is good (if you are working on windows and have ActiveState's perl installed, then search C:\Perl\html\index.html for "perlre") - if you prefer to look at some online page, googling for perlre will get you several online copies of the same page.
@/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using regexp with binary data
by Anonymous Monk on Aug 28, 2005 at 16:06 UTC |