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

topeg
 2007-09-27 00:48
#100046 #100046
User since
2006-07-10
2611 Artikel
BenutzerIn

user image
Meinst du sowas?

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/perl

use strict;
use warnings;

sub parse_link {
# $_=~s/^['"]|["']$//gs for(@_);
my %params = @_;
print "$_ = ".$params{$_}."\n" for keys %params;
return '<a href='.$params{LINK}.'>'.$params{INHALT}.'</a>';
}


my $string = 'Das ist Martin: [LINK="http://www.test.de" TARGET=_blank]klick hier[/LINK]';
print $string."\n";

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


Leg' mich jetzt aber schlafen. Schau Morgen früh noch mal vorbei.

View full thread RegEx: optionale Matches an Subroutine weitergeben