2017-01-10 17 views
-4

Я извлечу из href = "download.php? Id = 469979" this "OutDaughtered.S02E03.A.Quint.In.Crisis.720p.TLC.WEBRip.AAC2.0.x264- BTW.torrent»как преобразовать HTML в Regex

<a class="index" href="download.php?id=469979"><img src="styles/images/download.png" style="position:relative;bottom:1px;" alt="Download" border="0"> OutDaughtered.S02E03.A.Quint.In.Crisis.720p.TLC.WEBRip.AAC2.0.x264-BTW.torrent</a> 

у меня есть этот код:

# Search for filename 
my $match_filename=qr/<a class="index" href="download.php\/.*?\/.*?.torrent"><font color=.*?>(.*?).torrent<\/font><\/a> .Press/ms; 
my $filename_matches=$r->match('filename', $match_filename); 
if($filename_matches==0){ $r->err('Can not continue without filename, aborting!'); return 0;} 
my [email protected]$filename_matches[0]; 
$r->err("Filename: $filename"); 

у меня есть эта ошибка:

Failed to match filename 
Can not continue without filename, aborting! 

благодаря

+0

Скажите, что теперь? Что вы хотите делать, ПОЧЕМУ вы хотите это сделать и какого результата вы хотите достичь? – junkfoodjunkie

+0

Непонятно, что вы на самом деле спрашиваете. Что вы подразумеваете под «transform html to regex»? Регулярное выражение - это шаблон _search_, html - код разметки. У них нет ничего общего. Вы не можете «трансформировать» их друг в друга. – arkascha

+0

Может быть, вы хотите, чтобы регулярное выражение могло соответствовать этому коду? Объясните пожалуйста. –

ответ

0

PHP код:

<?php 
$re = '/(?<=">\s)(?:.*)(?=<)/m'; 
$str = '<a class="index" href="download.php?id=469979"><img src="styles/images/download.png" style="position:relative;bottom:1px;" alt="Download" border="0"> OutDaughtered.S02E03.A.Quint.In.Crisis.720p.TLC.WEBRip.AAC2.0.x264-BTW.torrent</a> 
'; 

preg_match_all($re, $str, $matches); 

// Print the entire match result 
print_r($matches); 
?> 

REGEXP:

/(?<=">\s)(?:.*)(?=<)/m 

Результат:

Array 
(
    [0] => Array 
     (
      [0] => OutDaughtered.S02E03.A.Quint.In.Crisis.720p.TLC.WEBRip.AAC2.0.x264-BTW.torrent 
     ) 

) 

См: https://regex101.com/r/vYGgJz/1

+0

, и я извлечу этот .torrent-файл из этого href = "download.php? id = 469979" –

+0

он будет извлекать текст без тегов , –

 Смежные вопросы

  • Нет связанных вопросов^_^