Here you can find the source of getMatcherWithSurroundingTags(String xml, String tag)
public static Matcher getMatcherWithSurroundingTags(String xml, String tag)
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static Matcher getMatcherWithSurroundingTags(String xml, String tag) {/*from w ww .j a v a 2 s . com*/ String regexCode = "(<" + tag + ".*?>)(.*?)(</" + tag + ">)"; Matcher m = regexGetMatcherForPattern(xml, regexCode); return m; } public static Matcher regexGetMatcherForPattern(String string, String pattern) { if (string == null || pattern == null) { return null; } /** * strip newline characters because it doesn't work well with this. */ // string = string.replace("\n", ""); Pattern p = Pattern.compile(pattern, Pattern.DOTALL | Pattern.MULTILINE); Matcher m = p.matcher(string); return m; } }