Thread Problem mit Match Anweisung und RegEx (9 answers)
Opened by Corni_Cornflake at 2017-08-20 15:38

MarkusH
 2017-08-20 17:24
#187267 #187267
User since
2012-04-08
161 Artikel
BenutzerIn
[default_avatar]
So vielleicht?

Code (perl): (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
#!/usr/bin/perl -w
use strict;

#probevariablen
my $normalText= "Bla bla blabla bla. Timo macht sein Zimmer sauber. Er vergisst das Staubsaugen.";

my @felder= split(/(\.|,|\?|\!|:|;)/,$normalText);
my @saetze = ();
my @nomen = ();

for(my $i = 0; $i <= $#felder; $i+=2) {
    push(@saetze, join('',$felder[$i], $felder[$i+1]));
}

foreach my $satz (@saetze) { 
        if ($satz =~ m/\b(er|sie)\b/gi) {
            push(@nomen,$1);
        }
        else {
            print "$satz\n";
        }
}

foreach (@nomen) {
    print "$_\n";
}


Zu Deinem Satzzeichenproblem sagt die Doku.
Anything in EXPR that matches PATTERN is taken to be a separator that separates the EXPR into substrings (called "fields") that do not include the separator. Note that a separator may be longer than one character or even have no characters at all (the empty string, which is a zero-width match).
$q =~ /(bb|[^b]{2})/

View full thread Problem mit Match Anweisung und RegEx