1
2
3
4
5
6
%hRegex = %{$hRegexAll{getkurl}};
if($anzeigeURL =~ /$hRegex{regex}/$hRegex{after}){
$anzeigeURL = $1;
}else{
$anzeigeURL = $aKurl[0];
1
2
3
4
5
6
getkurl => {
before => "",
regex => "((https?:\/\/)?([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;:~=%!]*)(\.\w{2,})?)*\/?)",
after => "g",
replace => "",
}
QuoteBei substitutionen habe iche s nun über eval erledigt da soweit ich es mitbekommen habe die Regex nicht interpretiert werden wenn diese aus den Variablen kommen.
1
2
3
4
5
6
7
8
9
10
11
12
13
perl -wl
my $search = 'aaa';
my $replace = '111';
my $text = 'aaabbbccc';
$text =~ s/$search/$replace/;
print ">$text<\n";
^D
>111bbbccc<
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
my %HoH = (
domain => {
before => "s",
regex => " \| .*\.\w*",
after => "g",
replace => "",
},
amazonde => {
before => "s",
regex => " - Amazon.de",
after => "g",
replace => "",
},
linetrenner => {
before => "s",
regex => "<br \/>",
after => "g",
replace => "{@}",
},
clearhtml => {
before => "s",
regex => "<.+?>",
after => "g",
replace => "",
},
clearlastwhite => {
before => "s",
regex => "\s+\$",
after => "",
replace => "",
},
checkpos => {
before => "",
regex => "^(\d+\.?\d*|\.\d+)\$",
after => "",
replace => "",
},
clearebay => {
before => "s",
regex => " bei ebay\$",
after => "i",
replace => "",
},
getkurl => {
before => "",
regex => "((https?:\/\/)?([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;:~=%!]*)(\.\w{2,})?)*\/?)",
after => "g",
replace => "",
},
);
return %HoH;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
sub subst {
#paramater holen
my ($search, $replace, $mod) = @_;
if (my $eval = $mod =~ s/e//g) {
$replace = qq{'$replace'};
$replace = "eval($replace)" for 1 .. $eval;
} else {
$replace = qq{"$replace"};
}
if($mod eq "g"){
sub {s/$search/$replace/gee};
}else{
sub {s/(?$mod)$search/$replace/ee};
}
}
1
2
3
4
5
6
%hRegex = %{$hRegexAll{domain}};
$sub = subst($hRegex{regex}, $hRegex{replace}, $hRegex{after});
$_ = $sHeader;
$sub->();
$sHeader = $_;