Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
Issue #847
  • Loading branch information
rsoika committed Jan 2, 2024
1 parent fac515d commit 4597d57
Showing 1 changed file with 8 additions and 7 deletions.
Expand Up @@ -159,23 +159,24 @@ public static List<String> findTags(String content, String tag) {

/**
* This method find not-empty tags inside a string and returns a list with all
* tags.
* tags including the tag itself.
* <p>
* e.g.: {@code<date field="abc">def</date>}
* <p>
* <strong>Note:</strong> To fine also empty tags use 'findTags'
* <strong>Note:</strong> To find also empty tags use 'findTags'
*
* @param content - XML data
* @param tag - XML tag
* @return
*/
public static List<String> findNoEmptyTags(String content, String tag) {
List<String> result = new ArrayList<String>();
String regex = "<" + tag + ".*>((.|\n)*?)<\\/" + tag + ">";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(content);
while (m.find()) {
result.add(m.group());
// Use a regular expression to extract the tag
String regex = "(<" + tag + "[^>]*>[\\s\\S]*?</" + tag + ">)";
Pattern pattern = java.util.regex.Pattern.compile(regex);
Matcher matcher = pattern.matcher(content);
while (matcher.find()) {
result.add(matcher.group());
}
return result;
}
Expand Down

0 comments on commit 4597d57

Please sign in to comment.