Das sollte Funktionieren:
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
#!/usr/bin/perl
use strict;
use warnings;
sub parse
{
my %params = @_;
# my @l=@_; print join('|',@l)."\n----\n";
print "$_ = ".$params{$_}."\n" for keys %params; print "#####\n";
if(exists($params{BILD}))
{ return '<img src='.$params{BILD}.'>'; }
elsif(exists($params{LINK}))
{ return '<a href='.$params{LINK}.'>'.$params{INHALT}.'</a>'; }
elsif(exists($params{ZITAT}))
{ return '<pre>'.$params{INHALT}.'</pre>'; }
elsif(exists($params{HEADLINE}))
{ return '<h>'.$params{INHALT}.'</h>'; }
else
{ return "!!Unbekannter Befehl!!"}
}
sub rsplit
{
my @v=@_;
# print join('|',@v),"\n";
return ($v[2]!~/=/?($v[1],''):(),$v[4]?('INHALT',$v[4]):(),$v[3]?(map{split(/\s+(?=\w+$)/,$_)}split(/\s*=\s*/,$v[2]=~/=/?$v[0]:$v[3])):());
}
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]
[ZITAT]Dies ist ein Zitat[/ZITAT] oder:
[HEADLINE]Dies ist eine Überschrift[/HEADLINE]
[HEADLINE SIZE=3]text[/HEADLINE]
';
print $string."\n#####\n";
$string =~ s|\[((\w+)(\s*=?s*)(.*?))\](?:(.+?)\[/\2\])?|parse(rsplit($1,$2,$3,$4,$5?$5:''))|gse;
print $string."\n";
Aber etwas ist seltsam. Wenn ich den Code aus 'rsplit' in die Regexp setze (und die Variablen $1..$5 anpasse) so funktioniert es in sofern nicht, als $5 nicht korrekt als leer oder gefüllt erkannt wird (mal funktioniert es mal nicht).
Aber so wie es da jetzt steht funktioniert es.
Sind dir in der Zwischenzeit noch ein paar Features eingefallen die noch Fehlen? ;-)