输入只能包括 '<','>','and','or',以及数字
开头只能为 '<','>'或数字

解决方案 »

  1.   

    正确输入如:
    >100 and <50
    >100 or <50
      

  2.   

    不好意思,你能再说清楚一点吗?
    输入只能是
    >100 and <50
    >100 or <50
    这种格式吗?
      

  3.   

    我按我得理解写了一个,^_^
    import java.util.regex.*;
    class  fjs{
    public static void main(String [] args){
    String s= ">100 or <50";
    Pattern pa = Pattern.compile("[><\\d]+ (and|or) [><\\d]+");
    Matcher ma = pa.matcher(s);
    if(ma.find()){
    System.out.println(ma.group());
    }
    }
    }
      

  4.   

    String txt =">100 and <50";
    if( txt.matches("^(>|<|\\d)(\\d)+\\s+(and|or)+\\s+(<|>|\\d)+") ){
    System.out.println("mat");
    }else{
    System.out.println("not mat");
    }
      

  5.   

    String txt=">50 and <100";
    if(/^>(\\d+)( and | or )<(\\d+)$/.text(txt))System.out.println("right");