2013年10月29日星期二

Seeking a simple regex

http://aabb.com/12sf/xxoo/ ab23.txt
I want to get the last name of the file , find the regular rules .
------ Solution ---------------------------------------- ----

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

------ Solution ------------------------------ --------------
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);
    }
}

------ Solution -------------------- ------------------------


dog brother V5 ..
------ Solution ----------------------- ---------------------
Cougerenao , make a

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));
}

------ For reference only ----------------------------------- ----
front are the same as you ?

------ For reference only ---------------------------------- -----
  This reply was moderator deleted at 2013-10-29 08:24:56

------ For reference only ---------------------------------- -----
just learning regular expressions, come and look

没有评论:

发表评论