首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

正则婚配字符串

2013-01-18 
正则匹配字符串请问有什么比较好的办法提取一个字符串中所有符合正则匹配的字符串呢?正则表达式是邮箱的正

正则匹配字符串
请问有什么比较好的办法提取一个字符串中所有符合正则匹配的字符串呢?

正则表达式是邮箱的正则匹配。

[解决办法]
..............
Matcher类有个find方法啊

[解决办法]
        public static List<LabelValueBean> getList(String str) {      List<String> list = new ArrayList<String>();
              Pattern pattern = Pattern.compile("\\{@[A-Za-z0-9]+#\\}");
                 if(UtilValidate.isEmpty(str)){
             return null;
                    }
              Matcher matcher = pattern.matcher(str);
         while (matcher.find()) {


         if (!list.contains(matcher.group()))
                     list.add(matcher.group());
                   }
    List<LabelValueBean> tmpList = new ArrayList<LabelValueBean>();
             for(int i = 0; i<list.size(); i++){
                 String index = i+"";
                   tmpList.add(new LabelValueBean(index,(String)list.get(i)));
             }
               return tmpList;
          }


                 试试这个方法
                                                           

                                                  普科学生

热点排行