日期:2014-05-20  浏览次数:21038 次

正则表达式 匹配文件名后缀
希望在一行包含下载地址的字符串中找到下载地址  

String   source   =   "http:\\djfshgdfhgwma ";                           //s2+s1;
Pattern   p   =   Pattern.compile( "http\\:\\w+\\.wma ");  
Matcher   m   =   p.matcher(source);  

while   (m.find())   {
System.out.println( "Match   \ " "   +   m.group()   +   "\ "   at   positions   "
+   m.start()   +   "- "   +   (m.end()   -   1));

可是没有结果

请问为何   ?   如何处理后缀中的点号   ?

谢谢

------解决方案--------------------
Pattern p = Pattern.compile( "http:\\\\\\\\\\w+\\.wma ");


另外,你那个String source = "http:\\djfshgdfhgwma ";
是不是少了个 ". "
------解决方案--------------------
修正一下 Pattern p = Pattern.compile( "http:\\\\.*.wma ");
应该是Pattern p = Pattern.compile( "http:\\\\.+.wma ");