求一个简单的正则表达式

学无止境-逆流而上 2013-10-28 06:00:54
http://aabb.com/12sf/xxoo/ab23.txt
我想获取最后的文件名,求正则规则。
...全文
183 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
失落夏天 2013-10-29
  • 打赏
  • 举报
回复
凑个热闹,补一个

String url = "http://aabb.com/12sf/xxoo/ab23.txt";
		Matcher m = Pattern.compile(".*/(.*?.txt).*?").matcher(url);
		while(m.find()){
			System.out.println(m.group(1));
		}
ww-y 2013-10-29
  • 打赏
  • 举报
回复
刚好在学习正则表达式,过来瞧瞧
乔不思 2013-10-28
  • 打赏
  • 举报
回复
引用 3 楼 Inhibitory 的回复:
public class Hello {
    public static void main(String[] args) throws IOException {
        String url = "http://aabb.com/12sf/xxoo/ab23.txt";
        String name = url.replaceAll(".*/(.*)$", "$1");
        System.out.println(name);
    }
}
狗哥 V5..
Inhibitory 2013-10-28
  • 打赏
  • 举报
回复
public class Hello {
    public static void main(String[] args) throws IOException {
        String url = "http://aabb.com/12sf/xxoo/ab23.txt";
        String name = url.replaceAll(".*/(.*)$", "$1");
        System.out.println(name);
    }
}
teemai 2013-10-28
  • 打赏
  • 举报
回复

public class GetFileName {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		String s = "http://aabb.com/12sf/xxoo/ab23.txt";
		String file = s.substring(s.lastIndexOf("/")+1);
		System.out.println(file);
		
	}

}

打印:
ab23.txt
teemai 2013-10-28
  • 打赏
  • 举报
回复
前面的都是一样的吗?

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧