Thread Regex Frage (23 answers)
Opened by bianca at 2012-11-09 17:42

bianca
 2012-11-09 19:09
#163203 #163203
User since
2009-09-13
7016 Artikel
BenutzerIn

user image
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
27
28
29
30
#!/usr/bin/perl
use strict;
use warnings;

my @test;
push @test,'[Thu Nov 08 22:59:19 2012] [error] Hostname www.......de provided via SNI, but no hostname provided in HTTP request';
push @test,'[Fri Nov 09 09:49:30 2012] [error] [client 8.1.1.1] Can\'t modify constant item in scalar assignment at /script.pl line 16, near "\'schiess mich tot\';", referer: https://.......pl';
for (my $z = 0; $z < scalar @test; $z++) {
    print "Zeile $z: ";
    if (
        $test[$z] =~ 
/^\[
([^\]]+) # Datum
\]
\s+
\[
([^\]]+) # Fehler
\]
\s+
(?>\[\S+\s([^\]]+)\]\s+)? # falls [client ...] Lookahead 
(.+)
$
/x;
    ) {
        print "matcht 1=>$1< 2=>$2< 3=>$3< 4=>$4< 5=>$5< 6=>$6< 7=>$7<\n";
    }
    else {
        print "matcht nicht\n";
    }
}

Quote
syntax error at test.pl line 23, near "/x;"
(Might be a runaway multi-line // string starting on line 12)
syntax error at test.pl line 27, near "else"
Execution of test.pl aborted due to compilation errors.
10 print "Hallo"
20 goto 10

View full thread Regex Frage