public static List<LabelValueBean> getList(String str) {
List<String> list = new ArrayList<String>();
Pattern pattern = Pattern.compile("\\{@[A-Za-z0-9]+#\\}");
// Pattern p = Pattern.compile(">(\\d+)<");
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;
}
java 提取 字符串中 匹配一条正则表达式的字符串
最新推荐文章于 2024-07-27 04:47:30 发布
本文介绍了一个使用Java实现的方法,该方法利用正则表达式从字符串中提取特定格式的内容,并将其转换为带有索引的LabelValueBean列表。这种方法适用于处理包含特定标记的文本数据,例如从文档中抽取元数据。
4223

被折叠的 条评论
为什么被折叠?



