例如:String s="hello.txtmail.jpgworld.log";
最终要得到s1=hello.txt
         s2=mail.jpg
         s3=world.log

解决方案 »

  1.   

    首先要建立一个扩展名的列表。
    然后不断地匹配  *.txt, 如果不行就去匹配*.jpg, 直到把这个列表匹配完。不过正则的方式太慢了。手工写吧,很好玩。
      

  2.   

    默认扩展名是3个字节.
    String   s= "hello.txtmail.jpgworld.log"; 
    Matcher m = Pattern.compile("[^\\.]*\\.[a-z]{3}").matcher(s);
    while (m.find()) {
         System.out.println(m.group());
    }
      

  3.   

    public class String1
    {
    public static void main(String[] args)
    {
    String  s="hello.txtmail.jpgworld.log"; 
    String s1=s.substring(0,9);
    String s2=s.substring(9,17);
    String s3=s.substring(17,26);
    System.out.println("s1="+s1);
    System.out.println("s2="+s2);
    System.out.println("s3="+s3);
    }
    }
      

  4.   

        String s = "hello.txtmail.jpgworld.log";
        Matcher m = Pattern.compile(".*?\\.\\w{0,3}").matcher(s);
        while (m.find()) {
          System.out.println(m.group());
        }可以匹配后缀0-3个长度的文件名
      

  5.   

    如果后缀长度固定3个的话,可以进行分隔,否则没有办法的。public class Test {
        public static void main(String[] arg) {
            String str = "hello.txtmail.jpgworld.log";
            String[] strs = str.split("(?<=\\.\\w{3})");
            
            for(String s : strs) {
                System.out.println(s);
            }        
        }
    }
      

  6.   

    要建一个后缀名的列表的吧,
    文件名
    a.txt.jpg.log
    这个也是一个合法的log文件名