码迷,mamicode.com
首页 > 编程语言 > 详细

java 找出字符串之间的字符

时间:2015-04-18 14:22:10      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

 

 

技术分享
package lia.meetlucene;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class XMLReaderTest {

    public static List<String> match(String s) {
        List<String> results = new ArrayList<String>();
        Pattern p = Pattern.compile("<text>(.*?)</text>");
        // p = Pattern.compile("<icon>([\\w/\\.]*)</icon>");
        Matcher m = p.matcher(s);
        while (!m.hitEnd() && m.find()) {
            results.add(m.group(1));
        }
        return results;
    }

    public static void main(String[] args) throws IOException {
        String s = "<text>能找到前方红绿灯在何处吗 堵车堵的这个神奇啊</text><timestamp>1406595562</timestamp>";
        System.out.println(Arrays.toString(Unicode1.match(s).toArray(
                new String[0])));
    }
}
View Code

 

java 找出字符串之间的字符

标签:

原文地址:http://www.cnblogs.com/XDJjy/p/4437212.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!