Regex Problem

Bash, Shell, PHP, Python, Perl, CGI
greenrover
Posts: 203
Joined: 2004-12-17 19:34

Regex Problem

Post by greenrover » 2009-02-27 18:57

Hallo,

Beispielcode:

Code: Select all

my $result ="<tr><td>Uptime</td><td class="string">5 days 12 hours 20 min 40 s</td></tr>
<tr><td>Started at</td><td class="string">2009-02-22 06:25:07</td></tr>
<tr><th colspan="2">absolute (since start)</th></tr>
<tr><td>Requests</td><td class="string">44  req</td></tr>
<tr><td>Traffic</td><td class="string">183.86 kbyte</td></tr>
<tr><th colspan="2">average (since start)</th></tr>
<tr><td>Requests</td><td class="string">0  req/s</td></tr>
<tr><td>Traffic</td><td class="string">0.40  byte/s</td></tr>
<tr><th colspan="2">average (5s sliding average)</th></tr>
<tr><td>Requests</td><td class="string">0  req/s</td></tr>
<tr><td>Traffic</td><td class="string">0.00  byte/s</td></tr>";

$result =~ m/sliding average[[:space:]]*([0-9]+)[[:space:]]*req/g;
my $requests = $1;

$result =~ m/sliding average.*rn.*([0-9.]+)[[:space:]]*byte/g;
my $traffik = $1;

print  $requests;


durch den Zeilenbruch zwichen:
<tr><th colspan="2">average (5s sliding average)</th></tr>
<tr><td>Requests</td><td class="string">0 req/s</td></tr

geht der Regex nicht. in PHP würde ich es so machen:
/sliding average.*>([0-9]+)[[:space:]]*req/sU

bloß wie heisen die Modifier sU in Perl?

MFG Heiko

freddy36
Posts: 273
Joined: 2008-03-20 17:31

Re: Regex Problem

Post by freddy36 » 2009-02-27 22:12

/m und /s ?

greenrover
Posts: 203
Joined: 2004-12-17 19:34

Re: Regex Problem

Post by greenrover » 2009-03-01 03:20

Leider geht das nicht.

dotme
Posts: 150
Joined: 2004-12-15 16:48

Re: Regex Problem

Post by dotme » 2009-03-01 12:19

In der ersten RegEx

Code: Select all

m/sliding average[[:space:]]*([0-9]+)[[:space:]]*req/g;

fehlt doch zumindest ein ".*?" hinter "average", da eine schliessende Klammer nun mal nicht zu [:space:] (s) gehört. CRLF sind nur im Zusammenhang mit ^ bzw. $ spezielle Leerzeichen.
BTW der Modifier "g" kann auch weg, da Du ja nur einen Match suchst.

freddy36
Posts: 273
Joined: 2008-03-20 17:31

Re: Regex Problem

Post by freddy36 » 2009-03-01 12:23

GreenRover wrote:Leider geht das nicht.

Der Regex stimmt auch nicht:

Code: Select all

#!/usr/bin/perl

$result ='<tr><td>Uptime</td><td class="string">5 days 12 hours 20 min 40 s</td></tr>
<tr><td>Started at</td><td class="string">2009-02-22 06:25:07</td></tr>
<tr><th colspan="2">absolute (since start)</th></tr>
<tr><td>Requests</td><td class="string">44  req</td></tr>
<tr><td>Traffic</td><td class="string">183.86 kbyte</td></tr>
<tr><th colspan="2">average (since start)</th></tr>
<tr><td>Requests</td><td class="string">0  req/s</td></tr>
<tr><td>Traffic</td><td class="string">0.40  byte/s</td></tr>
<tr><th colspan="2">average (5s sliding average)</th></tr>
<tr><td>Requests</td><td class="string">123  req/s</td></tr>
<tr><td>Traffic</td><td class="string">0.00  byte/s</td></tr>';

if($result =~ m/sliding average.*>([0-9]+)[[:space:]]*req/s) {
        print "found: $1n"
} else {
        print "not foundn"
}

funktioniert.

greenrover
Posts: 203
Joined: 2004-12-17 19:34

Re: Regex Problem

Post by greenrover » 2009-03-01 14:17

mercy, bis auf das s am End hatte ich es so am Anfang.

Dank dir.