是这样吗? public class testPattern { public static void main(String[] args) { String s = "我-->xx,你-- >yy,他- - > zz。"; Pattern p = Pattern.compile(",|。"); Matcher m = null; String[] arr = p.split(s); for (int i = 0; i < arr.length; i ++) { p = Pattern.compile("-->"); m = p.matcher(arr[i]); if (!m.find()) { System.out.println(arr[i]);//or do something } } } }我也是初学者
【】表示一个字符,所以这个表达式是匹配非"a","b","c"的一个字符
所以不是楼主需要的
String s="dfdabc";
Matcher m=p.matcher(s);
if(m.find()){
System.out.println("存在ABC");
}else{
System.out.println("不存在ABC");
}
var patrn=/^(\w)[a]{1}[b]{1}[c]{1}^(\w)$/
if(!patrn.exec(value)){
alert("不包含abc");
}
如果不用通用表达式也可以啊,一般是怎么解决这样的问题的呢?
js中的做法在java中好象不行吧?我试了试不行哦
public class testPattern {
public static void main(String[] args) {
String s = "我-->xx,你-- >yy,他- - > zz。";
Pattern p = Pattern.compile(",|。");
Matcher m = null;
String[] arr = p.split(s);
for (int i = 0; i < arr.length; i ++) {
p = Pattern.compile("-->");
m = p.matcher(arr[i]);
if (!m.find()) {
System.out.println(arr[i]);//or do something
}
}
}
}我也是初学者
hxzg001的那个如果没办法分割的话怎么办?或分割靠的就是-->?不过你给了我一个很好的提示,我还没仔细想,一会去试试...
Pattern p=Pattern.compile("-->");
String s="df-->aaaaa";
Matcher m=p.matcher(s);
if(!m.find()){
System.out.println("not found.");//Do something.
}else{
System.out.println("found.");//Do nothing.
}
}