W
Wolfgang Thomas
I have a line of the following format:
string length followed by colon followed by the actual
string.
To extract the string with the correct length I use the
following regular expression:
my $s = "3:abcd";
$s =~ /([\d]+)
.{\1})/;
print "$1\n";
print "$2\n";
However this does not match. Neither $1 nor $2 become
defined. If I replace \1 with 3 it works as expected,
I get 3 in $1 and "abc" in $2.
I have studied the "Perl Programming" book and
the active perl regex documentation, but could not
find a restriction that backreferences must not be
used inside quantifiers.
What am I doing wrong?
string length followed by colon followed by the actual
string.
To extract the string with the correct length I use the
following regular expression:
my $s = "3:abcd";
$s =~ /([\d]+)
print "$1\n";
print "$2\n";
However this does not match. Neither $1 nor $2 become
defined. If I replace \1 with 3 it works as expected,
I get 3 in $1 and "abc" in $2.
I have studied the "Perl Programming" book and
the active perl regex documentation, but could not
find a restriction that backreferences must not be
used inside quantifiers.
What am I doing wrong?