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输出出来。
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输出出来。
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));
}
}
}
String regex="([^/abc])";
String s="/abcw";
Matcher matcher = Pattern.compile(regex).matcher(s);
if (matcher.find()) {
System.out.println(matcher.group(1));
}
}如果是上面的代码话,会输出w,我的意思是只要包含abc,就什么也不输出
replace("");
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);
}
}
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.*"))用“非”操作,我的意思我的正则表达式,直接就能判断出来
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));
}
}
好像可以.
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));
}
}
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的