Perl Reg ex matching problem $trailer =~/00fd00.*00fc00/;
I'm trying to extract the characte开发者_开发问答rs: 328c1e460b000a2020202020200000
01e000000fd00328c1e460b000a202020202020000000fc00434f4
I'm using Perl on Windows XP and have tried:
$trailer =~/00fd00.*00fc00/;
$trailer =~/00fd00\w+00fc00/;
for example:
$trailer ="01e000000fd00328c1e460b000a202020202020000000fc00434f4";
print"Original $trailer\n";
#$trailer =~/00fd00.*00fc00/;
$trailer =~/00fd00\w+00fc00/;
print "Final $trailer\n";
The output is:
Original 01e000000fd00328c1e460b000a202020202020000000fc00434f4
Final 01e000000fd00328c1e460b000a202020202020000000fc00434f4
You can do something like:
$trailer =~ s/.*00fd00(.*)00fc00.*/$1/;
A plain match will not alter the variable itself, you need a substitution.
You can use regex captures:-
my $trailer ="01e000000fd00328c1e460b000a202020202020000000fc00434f4";
my ($trailer_extract) = $trailer =~/00fd00(\w+)00fc00/;
print "Original $trailer\n";
print "Final $trailer_extract\n";
This has the advantage over substitutions of leaving $trailer intact if you still need to reference the non-extracted string elsewhere in your code.
精彩评论