形如"ed.txt*2343rdgrgs3*,fgf.rar*sdf435hf*",需要使用正则表达式删除两段*号之间(包含*)的字符,请高手指导

解决方案 »

  1.   

    public class MainDemo
    {    public static void main(String []args)
        {      
         String regex="\\w{0,}\\.{1}\\w{0,}\\*\\w{0,}\\*";
         String s="ed.txt*2343rdgrgs3*";
         if(s.matches(regex)){
         System.out.println("success");
         System.out.println(s.replace("*", ""));
         }else{
         System.out.println("fail");
         }
        }
    }
      

  2.   


    public static void main(String[] args) {
    String str = "ed.txt*2343rdgrgs3*,fgf.rar*sdf435hf*";
    str = str.replaceAll("\\*.*?\\*", "");
    System.out.println(str);
    }
      

  3.   

    public class MainDemo
    {    public static void main(String []args)
        {      
         String str = "ed.txt*2343rdgrgs3*,fgf.rar*sdf435hf*";
            str = str.replaceAll("\\*.*?\\*","");
            System.out.println(str);
        }
    }
      

  4.   

    public static void main(String[] args) {

    String str = "ed.txt*2343rdgrgs3*,fgf.rar*sdf435hf*";
    str = str.replaceAll("\\*.*?\\*","");
    System.out.println(str);
    }
      

  5.   

    public static void main(String[] args) {

    String str = "ed.txt*2343rdgrgs3*,fgf.rar*sdf435hf*";
    str = str.replaceAll("\\*.*\\*","");
    System.out.println(str);
    }
    Greedy 数量词