对一个字符串进行处理:
如果它以"; Secure"结尾,我需要取出"; Secure"前面的字符串
如果不以"; Secure"结尾,需要得到整个字符串。如何用正则表达式操作?

解决方案 »

  1.   

    那不要正则表达式啊直接用 String类的 endWith即可String a = "dddddddddddddd ; Secure";a = a.endsWith("; Secure") ? a.subString(/*具体参数就是length - 8*/) : a;
      

  2.   

    System.out.println("adfasf; Secureasdfds; Secure".replaceAll("; Secure$", ""));
      

  3.   


    String s = "....";
    Matcher m = Pattern.compile("(; Secure)$").matcher(s);
    String news = m.replaceAll("");
      

  4.   

    不是要编程,是要通过正则表达式配置Apache
    有人知道,正则表达式要怎么写?
      

  5.   

    ^.+(?=; Secure$)|^.+(?!; Secure$)
      

  6.   

    试写了下. String str1="Class Object is the root of the class hierarchy.; Secure ";
    String str2="Every class has Object as a superclass.; Secure  All objects, including arrays, implement the methods of this class.cure ";
    String regex="(.+)(?:; Secure )$";
    Pattern p=Pattern.compile(regex);
    str2=str1;
    Matcher m=p.matcher(str2);
    if(m.matches()){
    System.out.println(m.group(1));
    }else{
    System.out.println(str2);
    }