String regEx = "(?=\\[/code]).+?(?<=\\[code\\=\\])"; Pattern pattern=Pattern.compile(regEx); Matcher matcher=pattern.matcher(elm1);//源代码片段来自云代码http://yuncode.net