public class Test01 {
public static void main(String[] args) {
                  String regex=""
                  String s="/abc";
Matcher matcher = Pattern.compile(regex).matcher(s);
if (matcher.find()) {
System.out.println(matcher.group(1));
}
}
}求正则表达式regex,能够实现s不是"/abc",就可以把s输出出来。

解决方案 »

  1.   

    if(!s.equals("/abc"))System.out.println(s);
      

  2.   

    非要用的话:public class Test01 {
    public static void main(String[] args) {
                      String regex="(/abc)"
                      String s="/abc";
    Matcher matcher = Pattern.compile(regex).matcher(s);
    if (matcher.find()) {
    System.out.println(matcher.group(1));
    }
    }
    }
      

  3.   

    可能是我的意思没有说明白 public static void main(String[] args) {
             String regex="([^/abc])";
                 String s="/abcw";
    Matcher matcher = Pattern.compile(regex).matcher(s);
    if (matcher.find()) {
    System.out.println(matcher.group(1));
    }
    }如果是上面的代码话,会输出w,我的意思是只要包含abc,就什么也不输出
      

  4.   

    你replace就可以了
    replace("");
      

  5.   

    写不出来..........可以用indexOf
      

  6.   

    这意思?public class Test3 {
    public static void main(String[] args) {
    String[] as = {"/abcw", "isudygq", 
    "abchiod", "shdfabc", "dasbec"};
    for(String s : as)
    if(!s.matches(".*abc.*"))
    System.out.println(s);
    }
    }
      

  7.   

    public class Test3 {
    public static void main(String[] args) {
    String[] as = {"/abcw", "isudygq", 
    "abchiod", "shdfabc", "dasbec"};
    for(String s : as)
    if(!s.matches(".*abc.*"))
    System.out.println(s);
    }
    }
    我不想if(!s.matches(".*abc.*"))用“非”操作,我的意思我的正则表达式,直接就能判断出来
      

  8.   

    String str[] =new String[]{"abcd","123","adc","1abc"};
    Pattern p = Pattern.compile("(?!abc)^(.*)$(?<!abc)");
    for(int i=0;i<str.length;i++){
    Matcher m = p.matcher(str[i]);

    if(m.find()){
    System.out.println(m.group(1));
    }
    }
    好像可以.
      

  9.   

    哦,这回好象可以了:
    String str[] =new String[]{"abcd","123","adc","1abc","eabcd"};
    Pattern p = Pattern.compile("^(?!.*abc)(.*)$");
    for(int i=0;i<str.length;i++){
    Matcher m = p.matcher(str[i]);

    if(m.find()){
    System.out.println(m.group(1));
    }
    }
      

  10.   

    package ch01;import java.util.regex.Matcher;
    import java.util.regex.Pattern;public class Test3 {
    public static void main(String[] args) {
    String str[] =new String[]{"abcd","123","adc","1abc","eabcd"}; Pattern pt=Pattern.compile(".*abc.*");
    for(int i=0;i<str.length;i++){
    Matcher m=pt.matcher(str[i]);
    boolean b=m.matches();
    if(!b)
    System.out.println(str[i]);
    }
    }
    }
    最简单也是最有效的方法,只输出不含有abc的