erlug
[Top] [All Lists]

RE: [Erlug] regex in perl

To: "'erlug@xxxxxxxxxxxxxx'" <erlug@xxxxxxxxxxxxxx>
Subject: RE: [Erlug] regex in perl
From: Alessandro Forghieri <Alessandro.Forghieri@xxxxxxxxxx>
Date: Thu, 6 Jun 2002 19:16:55 +0200
Saluti.

Un perlmonk mi ha risposto cosi' - vedi sotto - il che e' anche abbastanza
interessante.
Tutti e due i comportamenti (incluso il backslash di piu') mi sembrano
altamente anomali,
ma almeno la soluzione con \Q e \E non consuma il tasto '\'. Certo se si
vuola costruire dinamicamente una regex che contiene anche metacratteri e'
un casino.

Cheers,
alf


I've tried to play with this code: 

$orig='aaa([\+\-]{1})bbb';
$res = '([\\+\\-]{';
$qres = '\\Q$res\\E';

$str=$orig;
$str =~ s!\Q$res\E!!;
print "Replace against variable quoted => $res <=: $str\n";

$str=$orig;
$str =~ s!$qres!!;
print "Replace against variable quoted => $qres <=: $str\n";

Examining its output: 

Replace against variable quoted => ([\+\-]{ <=: aaa1})bbb
Replace against variable quoted => \Q$res\E <=: aaa([\+\-]{1})bbb

I notice that placing special metacharacters inside your variable doesn't
make them 'effective'. However, when they are outside of the variable, they
get 'noticed' by the regular expression parser. So, could it be the answer
to your inquiry? ;-) 




<Prev in Thread] Current Thread [Next in Thread>