2011-01-25 35 views
0

如果給定的URL使用正則表達式,我們需要驗證searchStringKeyword在下載URL中搜索電影名稱

例如

if URL : http://thepiratebay.org/torrent/3962906/Mera.Naam.Joker.1970.LiMiTED.DVDRiP.XviD-D3Si" 

searchStringKeyword : Mera Naam Joker 
expected outcome: true 

searchStringKeyword : DVDRiP 
expected outcome: true 

searchStringKeyword : Speed 
expected outcome: false 

任何幫助將高度讚賞。

阿米特

+0

另一個BitTorrent客戶端*正是*世界所需要的。 – 2011-01-25 08:06:29

回答

0

如果你正在使用正則表達式點菜PERL,圖案會是這些:

/DVDRip/ 
/Mera\W+Naam\W+Joker/ 
/Speed/ 
+0

嗨澤維爾,我正在研究Java ..... – Amit 2011-01-25 08:18:51

1

你的例子並不是相當全面。

如果你想匹配的話「梅拉」的任何URL「納摩」和「小丑」,按照這個順序,但任何數量的字符將它們分開,你可以使用this

/Mera.*Naam.*Joker/ 

如果你希望這是一個且只有一個分隔符,但你不在乎這個角色是什麼,你可以使用this

/Mera.Naam.Joker/ 

如果你想有成爲之間的單個.字符字樣,如this

/Mera\.Naam\.Joker/ 
+0

嗨,我試過下面:
String s_url =「http://thepiratebay.org/torrent/3962906/Mera.Naam.Joker.1970.LiMiTED.DVDRiP。 XviD格式,D3Si「;
\t \t \t String regex =「/ DVDRip /」;
\t \t \t String regex_name =「/Mera\\.Naam\\.Joker/」;
\t \t \t \t \t \t圖案P = Pattern.compile(正則表達式);
\t \t \t Matcher m = p.matcher(s_url);
\t \t \t System.out.println(「Found DVD in url」+ m.matches());

\t \t \t \t \t \t圖形PP = Pattern.compile(regex_name);
\t \t \t Matcher mm = pp.matcher(s_url);
\t \t \t System.out.println(「Found name in url」+ mm.matches());
但兩者都返回false。 – Amit 2011-01-25 08:13:55