RegEx用于处理某些字符的大写和小写

时间:2013-02-28 18:37:17

标签: java

public class BioHomework {
  public static void main(String[] args) {
    if(args.length < 2) {
       throw new IllegalArgumentException("two args required");
    }
    String sequence = args[1];
    if (!sequence.toLowerCase().matches("[atgc]{10,20}")){
      throw new IllegalArgumentException("second arg should be 'atgc' string between 10 and 20 characters");
    }
    if ("u".equals(args[0])) {
      System.out.println(sequence.toUpperCase());
    } else if ("l".equals(args[0])) {
      System.out.println(sequence.toLowerCase());
    } else {
      throw new IllegalArgumentException("first argument must be either 'u' or 'l'");
    }

  }
}

如何通过给出命令行参数让dna序列以大写和小写形式打印。以上代码只给我一条消息。

1 个答案:

答案 0 :(得分:0)

只需更改RegEx即可接受大写或小写字符。从

[atgc]{10,20}

[aAtTgGcC]{10,20}