java 找出字符串之间的字符

 

 

java 找出字符串之间的字符
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)