java 代码
- public static void main(String[] args) {
- Pattern p = Pattern.compile(regex);
- Matcher m = p.matcher(text);
- while (m.find()) {
- System.out.println(m.group(1));
- }
- }
我要匹配的字符串为:
xml 代码
- String regex = "<a href=\"/theater/cate.php\\?id=(\\d*)\".*?</a>";
- String text = "< a href=\"/theater/cate.php?id=236\">交互商品演示</a><a href=\ "/theater/cate.php?id=253\" class=\"colorRed\">其他交互演示</a>< a href=\"/theater/cate.php?id=255\">网站片头</a>";
打印出:
236
253
255