符合要求的匹配
  '%_%'    单引号百分号开头,百分号单引号结尾,中间有一个到多个下划线,并还有可能有其他字符如:'%ABCS_DAFDAS%' 
'%___DAFDAS%' 
'%DAF_DAS__%' 

解决方案 »

  1.   


    public static void main(String[] args) {
            String str = "'%ABCS_DAFDAS%'";
            System.out.println(str.matches("'%\\w*?_\\w*?%'"));
        }
      

  2.   

    public void run(){
    String[] strs = new String[] {
    "'%ABCS_DAFDAS%'",
    "'%___DAFDAS%'",
    "'%DAF_DAS__%'"};
    for(String str : strs){
    System.out.println(str.matches("'%[^%]*%'"));
    }
    }
      

  3.   

    楼上正解
    当然你也可以这样 String rex=['%].*[_]+.*[%']";
               或者 String rex = "^'%.*[_]+.*%'$";
    推荐 String rex = "^'%.*[_]+.*%'$";  有判断开始和结束字符