import java.util.Arrays; import java.util.regex.Pattern; import java.util.regex.Matcher; /** * java.util.regex包负责对字符序列进行正则表达式匹配 Pattern负责编译 * Matcher负责匹配 */ public class Main { public static void main(String[] args) { String strData = "eoptghhhggggggfgktvdrhkj,5-_h /artk"; String strReg1 = "eopt"; String strReg2 = "([\\w\\W]+)"; String strReg3 = "artk"; String strReg = strReg1 +strReg2 +strReg3; System.out.println(strReg); mRegEx(strData, strReg); } private static void mRegEx(String strData,String strReg) { Pattern p = Pattern.compile(strReg); Matcher m = p.matcher(strData); boolean b = m.matches(); System.out.println(b); //String r = m.group(0); //System.out.println(r); } }