首页 > 代码库 > 正则匹配查找模板

正则匹配查找模板

Pattern  p=Pattern.compile("[a-zA-Z0-9]+");
Matcher w=p.matcher(str);
            while(w.find()){
                String word=w.group();
                int index=w.start();
                if(!dictionary.containsKey(word)){
                    ArrayList<Location> list=new ArrayList<Location>();
                    dictionary.put(word, list);
                }
                ArrayList<Location> list=dictionary.get(word);
                Location pair=new Location(row,index);
                list.add(pair);
                dictionary.put(word, list);
                //System.out.println(index);
            }

 

正则匹配查找模板