Re: regex problem
- From: Ben Morrow <ben@xxxxxxxxxxxx>
- Date: Mon, 15 Jun 2009 03:26:06 +0100
Quoth Charlton Wilbur <cwilbur@xxxxxxxxxxxxxx>:
"BM" == Ben Morrow <ben@xxxxxxxxxxxx> writes:
BM> Quoth Charlton Wilbur <cwilbur@xxxxxxxxxxxxxx>:
>> >>>>> "s" == sstark <sstark@xxxxxxxxxx> writes:
BM> [ sstark's code was
BM> $line =~ s/^$prev//;
BM> ]
s> Why isn't it deleting the value of $prev in $line?
>> Because ^ doesn't do what you think it does, and it only works in
>> the code you have there out of pure luck and coincidence.
BM> Please explain further. ^ means 'match at the beginning of the
BM> string', unless /m is given, in which case it means 'match at
BM> the beginning of any line'. How is this not what the OP thought
BM> it meant?
Because the strings he wants are at the start of the strings he's
looking at purely by accident -- it's not part of his specification.
The relevant bits of the original code are
while($line =~ /^(.*?href\s*=\s*\")([^\"]+)(\".*)/i){
my $prev =$1;
# ...
$line =~ s/^$prev//;
so it's *not* coincidence that the string he's searching for is at the
beginning. If it wasn't we wouldn't have got here in the first place
(note the ^ at the start of the original match).
Ben
.
- References:
- regex problem
- From: sstark
- Re: regex problem
- From: Charlton Wilbur
- Re: regex problem
- From: Ben Morrow
- Re: regex problem
- From: Charlton Wilbur
- regex problem
- Prev by Date: Re: regex problem
- Next by Date: FAQ 2.14 Where are the archives for comp.lang.perl.misc?
- Previous by thread: Re: regex problem
- Next by thread: YAPC::NA at CMU
- Index(es):
Relevant Pages
|