Thread RegEx: optionale Matches an Subroutine weitergeben (31 answers)
Opened by Froschpopo at 2007-09-25 23:57

topeg
 2007-09-27 07:49
#100049 #100049
User since
2006-07-10
2611 Artikel
BenutzerIn

user image
achso.
Du willst sowas:
Code: (dl )
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
#!/usr/bin/perl

use strict;
use warnings;

sub parse {
my %params = @_;
print "$_ = ".$params{$_}."\n" for keys %params; print "#####\n";
if(exists($params{BILD}))
{
unless (-e $params{BILD})
{
return "!!Unbekannte Datei!!";
}
}
elsif(exists($params{LINK}))
{
return '<a href='.$params{LINK}.'>'.$params{INHALT}.'</a>';
}
else
{ return "!!Unbekannter Befehl!!"}
}


my $string =
'
Das ist Martin: [LINK="http://www.test.de" TARGET=_blank]klick hier[/LINK] Sein Bild: [BILD=martin.gif NAME="asd ass as" NAME2=hallo]
Das ist Bärbel: [LINK="http://www.test.de" TARGET=_blank]klick hier[/LINK] Ihr Bild: [BILD=baerbel.gif NAME="asd ass as" NAME2=hallo]
';
print $string."\n#####\n";

$string =~ s!\[((\w+).+?)\](?:(.+?)\[/\2\])?!parse((map{split(/\s+(?=\w+$)/,$_)}split(/\s*=\s*/,$1)),$3?('INHALT',$3):())!gse;
print $string."\n";

View full thread RegEx: optionale Matches an Subroutine weitergeben