现在有个字符串:"<test1>abc<test2>efg<test3>"
我想通过正则表达式得到< >里面的内容如 test1 test2 test3
请高手解答谢谢

解决方案 »

  1.   

    String regex = "<(.*?)>";
    ....
    while(xxx.find())
    System.out.print(xxx.group(1));
      

  2.   

    package com.xuyisen.monitor.test;import java.util.regex.Matcher;
    import java.util.regex.Pattern;public class Test { public static void main(String[] args) {
    String s = "<test1>abc<test2>efg<test3>";
    String regex = "<(.+?)>";
    Pattern p = Pattern.compile(regex);
    Matcher m = p.matcher(s);
    while(m.find()){
    System.out.println(m.group(1));
    }
    }
    }
      

  3.   


    package com.xuyisen.monitor.test;import java.util.regex.Matcher;
    import java.util.regex.Pattern;public class Test { public static void main(String[] args) {
    String s = "<test1>abc<test2>efg<test3>";
    String regex = "<(.+?)>";
    Pattern p = Pattern.compile(regex);
    Matcher m = p.matcher(s);
    while(m.find()){
    System.out.println(m.group(1));
    }
    }
    }