1.不包含字符:
例如不包含字符hede
^((?!hede).)*$
2.提取字符串
Pattern pattern = Pattern.compile("(?<=\\()(.+?)(?=\\))");
Matcher matcher = pattern.matcher("教师10(0010)");
while (matcher.find()) {
String value = matcher.group();
System.out.println(value);
}
String ip = "127.0.0.1";
String rtspStr = "rtsp://127.0.0.11:8935/live/5_abc";
Pattern pattern2 = Pattern.compile("(?<=//)(.+?)(?=:)");
Matcher matcher2 = pattern2.matcher(rtspStr);
while (matcher2.find()) {
String value = matcher2.group();
System.out.println(value);
}
/*
* 宽断言
*(?=exp) 匹配exp前面的位置
*(?<=exp) 匹配exp后面的位置
*(?!exp) 匹配后面跟的不是exp的位置
*(?<!exp) 匹配前面不是exp的位置
*
*/
3.参考资料
4.语法