比如一个字符串"iJ 0.P EN .P LUG. Gance Zhi-Hong Zhi Swtterbootu: + 886 2 2059 Osoo
 Fmc +.886 2 8797 2500 Moolle: + 886 928 :84 803
 E-mail: gotcezhu@epen-augcom OPEN-PLUG
 NO.18S. Zhcua S t Neihu D istpct Tooet cny I 1498. Toiwon, POe
 www. openyug con "要求写一个正则表达式
判断epen是它的一个字串
判断e p n是它的一个字串(注意中间是空格)
判断e  n是它的一个字串(注意中间有两个空格)这里必须考虑到换行符和其他任意空白字符有兴趣的来试试,多谢了

解决方案 »

  1.   

    你看这个有用吗
    String first = "epen";
    String str = "e p e n ";
    boolean is = false;
    byte[] bytess = str.getBytes(); // for (byte b : bytess) {
    // System.out.println(b);
    // } String resultStr = new String();
    for (byte b : bytess) { // 大空格 ASCII码 0
    // 小空格 ASCII码 32
    // 回车 ASCII码 13
    if (b == 0 || b == 13 || b == 32) {
    continue;
    } resultStr += new String(new byte[] { b }); }
    int isint=first.indexOf(resultStr);

    if (isint!=-1) {
    is=true;
    }
    System.out.println(is);
      

  2.   

    先以行來劃分字符,再用String的contains來判斷不是更好,更有效率