RapidShare Regular Expression
Coul开发者_运维知识库d anyone please help me to find a regular expression for new rapid sharelink
http://rapidshare.com/#!download|943dt|421184201|Tools.rar|7316
I would like to have something like this one
$str = 'blah http://rapidshare.com/#!download|943dt|421184201|Tools.rar|7316 blah';
if(preg_match_all('#http://rapidshare\.com/#!download|(.*?)|([^\s]+)#', $str, $m)) {
    var_dump($m);
}
Result
`
 array
  0 => 
    array
      0 => string 'http://rapidshare.com/#!download|943dt|421184201|Tools.rar|7316' (length=51)
  1 => 
    array
      0 => string '943dt' (length=5)
  2 => 
    array
      0 => string '421184201' (length=8)
 3 => 
    array
      0 => string 'Tools.rar' (length=8)
 4 => 
    array
      0 => string '7316' (length=8)`
Can you please try this regex:
$str = 'blah http://rapidshare.com/#!download|943dt|421184201|Tools.rar|7316 blah';
if(preg_match(
 '@http://rapidshare.com/#!download\|([^\|]+)\|([^\|]+)\|([^\|]+)\|([^\|\s]+)@',
    $str, $m)) {
   var_dump($m);
}
// prints
array(5) {
  [0]=>
  string(63) "http://rapidshare.com/#!download|943dt|421184201|Tools.rar|7316"
  [1]=>
  string(5) "943dt"
  [2]=>
  string(9) "421184201"
  [3]=>
  string(9) "Tools.rar"
  [4]=>
  string(4) "7316"
}
Update
Wasn't aware of presence of newline characters in the text. If that is the case use below code to remove newline chars first before matching against the regex:
preg_match(
 '@http://rapidshare.com/#!download\|([^\|]+)\|([^\|]+)\|([^\|]+)\|([^\|\s]+)@',
    str_replace("\n", "", $str), $m)
$string = "blah http://rapidshare.com/#!download|943dt|421184201|Tools.rar|7316 blah http://rapidshare.com/#!download|1233dt|123484201|Porn.rar|7232316";
preg_match_all("#http:\/\/rapidshare\.com\/([^\s]+)#is", $string, $matches);
$matches = $matches[0];
foreach($matches as $match){
    $pieces = explode("|", $match);
    unset($pieces[0]);
    $pieces[0] = $match;
    $result[] = $pieces;
}
print_r($result);
Result...
Array
(
    [0] => Array
        (
            [1] => 943dt
            [2] => 421184201
            [3] => Tools.rar
            [4] => 7316
            [0] => http://rapidshare.com/#!download|943dt|421184201|Tools.rar|7316
        )
    [1] => Array
        (
            [1] => 1233dt
            [2] => 123484201
            [3] => Porn.rar
            [4] => 7232316
            [0] => http://rapidshare.com/#!download|1233dt|123484201|Porn.rar|7232316
        )
)
@http://rapidshare\.com/#!download|(.*?)|(\d+)|([^\s]+)|(\d+)@
Given your example link, that should do it.
Regex is really the wrong tool for this, IMO. You should just use string manipulation to split it on | characters, then ignore the first string in the resulting array, which should be http://rapidshare.com/#!download. Should be simpler, faster, and easier to debug.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论