0
我有一个代码将字符串视为一个标签并将所有内容全部提取出来。在这种情况下:“abc </a > <a> def”。如何分离提取标签以获取两个字符串:“abc”和“def”?如何多次提取标签内容?
public static void main(String[] args) throws Exception {
Ex.findInTags("<a>((.*))</a>", "<a>abc</a> <a>def</a>");
}
public static void findInTags(String a, String b) {
Pattern pattern = Pattern.compile(a);
Matcher matcher = pattern.matcher(b);
if (matcher.find()) {
System.out.println(matcher.group(1));
}
}
我不是VotingToClose只是因为我有一些疑惑,但可能是以下副本:http://stackoverflow.com/a/1732454/598289 – SJuan76
可能重复的[RegEx匹配开放标记,除了XHTML自包含标记]( http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – baudsp