10 Einträge, 1 Seite |
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;
use Data::Dumper;
my $text = "Vorrede bla bla Anfang <<A>> Teil1 <<A>> Teil2 <<B>> Teil3 <<A>> Ende Nachrede.";
my $re = qr~Anfang <<A>> [^<]+ (<<A>>) [^<]+ (<<B>>) [^<]+ <<A>> Ende~;
print "text : [$text]\n",
"re : [$re]\n";
my @allmatch = $text =~ $re;
my ($m1, $m2, $m3) = ($`, $&, $');
print "allmatch: ", Dumper \@allmatch;
print "m1 : [$m1]\n",
"m2 : [$m2]\n",
"m2 : [$m3]\n";
1
2
3
4
5
6
7
8
9
text : [Vorrede bla bla Anfang <<A>> Teil1 <<A>> Teil2 <<B>> Teil3 <<A>> Ende Nachrede.]
re : [(?-xism:Anfang <<A>> [^<]+ (<<A>>) [^<]+ (<<B>>) [^<]+ <<A>> Ende)]
allmatch: $VAR1 = [
'<<A>>',
'<<B>>'
];
m1 : [Vorrede bla bla ]
m2 : [Anfang <<A>> Teil1 <<A>> Teil2 <<B>> Teil3 <<A>> Ende]
m2 : [ Nachrede.]
Vorrede bla bla Anfang <<A#14>> Teil1 <<A#8>> Teil2 <<B#1>> Teil3 <<A#9>> Ende Nachrede.
$reausdruckstext =~ s~>>~#\\d+>>~g;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my $text = 'Vorrede bla bla Anfang <<A#14>> Teil1 <<A#8>> Teil2 <<B#1>> Teil3 <<A#9>> Ende Nachrede.';
my $retext = 'Anfang <<A>> [^<]+ (<<A>>) [^<]+ (<<B>>) [^<]+ <<A>> Ende';
print "text : [$text]\n",
"retext : [$retext]\n";
$retext =~ s~>>~#\\d+>>~g;
my $re = qr~$retext~;
print "retext : [$retext]\n",
"re : [$re]\n";
my @allmatch = $text =~ $re;
my ($m1, $m2, $m3) = ($`, $&, $');
print "allmatch: ", Dumper \@allmatch;
print "m1 : [$m1]\n",
"m2 : [$m2]\n",
"m2 : [$m3]\n";
1
2
3
4
5
6
7
8
9
10
11
text : [Vorrede bla bla Anfang <<A#14>> Teil1 <<A#8>> Teil2 <<B#1>> Teil3 <<A#9>> Ende Nachrede.]
retext : [Anfang <<A>> [^<]+ (<<A>>) [^<]+ (<<B>>) [^<]+ <<A>> Ende]
retext : [Anfang <<A#\d+>> [^<]+ (<<A#\d+>>) [^<]+ (<<B#\d+>>) [^<]+ <<A#\d+>> Ende]
re : [(?-xism:Anfang <<A#\d+>> [^<]+ (<<A#\d+>>) [^<]+ (<<B#\d+>>) [^<]+ <<A#\d+>> Ende)]
allmatch: $VAR1 = [
'<<A#8>>',
'<<B#1>>'
];
m1 : [Vorrede bla bla ]
m2 : [Anfang <<A#14>> Teil1 <<A#8>> Teil2 <<B#1>> Teil3 <<A#9>> Ende]
m2 : [ Nachrede.]
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
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my $text = 'Vorrede bla bla Anfang <<A>> Teil1 <<A>> Teil2 <<B>> Teil3 <<A>> Ende Nachrede.';
my $retext = 'Anfang <<A>> [^<]+ (<<A>>) [^<]+ (<<B>>) [^<]+ <<A>> Ende';
print "Original:\n",
"text : [$text]\n",
"retext : [$retext]\n";
my $magicnumber = 0;
while ($text =~ s~(?<=\D)>>~#$magicnumber>>~) {
++$magicnumber;
}
$retext =~ s~>>~#\\d+>>~g;
my $re = qr~$retext~;
print "\nVeraendert:\n",
"text : [$text]\n",
"retext : [$retext]\n",
"re : [$re]\n";
my @allmatch = $text =~ $re;
my ($m1, $m2, $m3) = ($`, $&, $');
print "\nallmatch: ", Dumper \@allmatch;
print "m1 : [$m1]\n",
"m2 : [$m2]\n",
"m2 : [$m3]\n";
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Original:
text : [Vorrede bla bla Anfang <<A>> Teil1 <<A>> Teil2 <<B>> Teil3 <<A>> Ende Nachrede.]
retext : [Anfang <<A>> [^<]+ (<<A>>) [^<]+ (<<B>>) [^<]+ <<A>> Ende]
Veraendert:
text : [Vorrede bla bla Anfang <<A#0>> Teil1 <<A#1>> Teil2 <<B#2>> Teil3 <<A#3>> Ende Nachrede.]
retext : [Anfang <<A#\d+>> [^<]+ (<<A#\d+>>) [^<]+ (<<B#\d+>>) [^<]+ <<A#\d+>> Ende]
re : [(?-xism:Anfang <<A#\d+>> [^<]+ (<<A#\d+>>) [^<]+ (<<B#\d+>>) [^<]+ <<A#\d+>> Ende)]
allmatch: $VAR1 = [
'<<A#1>>',
'<<B#2>>'
];
m1 : [Vorrede bla bla ]
m2 : [Anfang <<A#0>> Teil1 <<A#1>> Teil2 <<B#2>> Teil3 <<A#3>> Ende]
m2 : [ Nachrede.]
1
2
3
4
5
6
my $text = 'Vorrede bla bla Anfang <<A>> Teil1 <<A>> Teil2 <<B>> Teil3 <<A>> Ende Nachrede.';
my @parts = split /\s*(<<[^>]+>>)\s*/, $text;
print join "\n", @parts;
print "\n";
1
2
3
4
5
6
7
8
9
10
~/test> perl test.pl
Vorrede bla bla Anfang
<<A>>
Teil1
<<A>>
Teil2
<<B>>
Teil3
<<A>>
Ende Nachrede.
my @parts = split /\s*(<<[^>]+>>)\s*/, $text;
<<[^<>]>>
10 Einträge, 1 Seite |