现在有类似<doc>abc</doc><title>3232</title> <doc>只要内容</doc>这么一个串,需要提取abc,3232,只要内容的节点内容
- public static List getContext(String html) {
- List resultList = new ArrayList();
- Pattern p = Pattern.compile(">([^</]+)</");//正则表达式 commend by danielinbiti
- Matcher m = p.matcher(html );//
- while (m.find()) {
- resultList.add(m.group(1));//
- }
- return resultList;
- }
- /**
- * @param args
- */
- public static void main(String[] args) {
- String a = "<doc>abc</doc><title>3232</title> <doc>只要内容</doc>";
- List list = getContext(a);
- System.out.println(list);
- }