java 怎么利用正则表达式从给定的字符串中取出匹配规则字符串
1个回答
2015-11-27
展开全部
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;
}
这个方法可以帮你
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;
}
这个方法可以帮你
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询