取反正则:^((?!要取反的正则表达式).)*$
示例:
import java.util.regex.Matcher;import java.util.regex.Pattern;public class Main {public static void main(String[] args) {// 匹配以test开头的字符串Pattern pattern = pile("^test");Matcher matcher = pattern.matcher("test11");System.out.println(matcher.find());// 匹配不是以test开头的字符串Pattern pattern2 = pile("^((?!^test).)*$");Matcher matcher2 = pattern2.matcher("hellotest");System.out.println(matcher2.find());}}