views:

116

answers:

5

Hey guys.

I am trying to match the FDSize: in the following:

Gid: 48 48 48 48 FDSize: 64 Groups: 48 425 VmPeak: 289928 kB

It comes from /proc/status

is not fixied length, and neither is the lines above or below.

Can any one help?

Thanks

A: 

But the term 'FDSize: ' always has the same length. So you just get the position at the end of that substring and the position of the following space. Everything in between will be the number I assume you wish to extract. No regular expression needed. strpos and substr should suffice.

tharkun
A: 

Try something like this:

preg_match_all('`FDSize: (\\d+)`s', $subject, $matches);
print_r($matches);
Kamil Szot
A: 

Not really sure why/how/when you have to do this. I should've asked questions before posting an answer but i didn't. Here are some ways to get that out of a line though...

$line = 'Gid: 48 48 48 48 FDSize: 64 Groups: 48 425 VmPeak: 289928 kB';

// in a loop...
echo current( explode(' ', end( explode( 'FDSize: ', $line ) ) ) );

// or

preg_match_all('~fdsize: (\d+)~i', $line, $matches);
Galen
A: 
$mystr='Gid: 48 48 48 48 FDSize: 64 Groups: 48 425 VmPeak: 289928 kB';
$str = explode(":",$mystr);
foreach($str as $k=>$word){
    if(strpos($word,"FDSize") !== FALSE){
        print $str[$k+1];
    }
}
You should always avoid loops if you can
Galen
that's bullshit. where did you get this notion.
A: 

try

preg_match_all("/FDSize:\s([0-9]+)/msiU", $data_in, $matches);

Ass3mbler