大家好,
我有一个内容串,其中的格式可能是这样的:
第一行
[smile=3]第二行
[smiley=5]第三行
第四行[smile=8]
第一个照片
[attachment]12[/attachment]
第六行
[attachment]63[/attachment]
结束行
我需要取里面的所有文字(就是:第一行 第二行 ...),并把其中[attachment]*[/attachment]中的内容取出来,当然是一个数组了.
我应该如何写代码?
String content = '.........................'; //这是内容串
String regex = "\\[smile=\\d+\\]";
String title = content.replaceAll(regex, ""); //去掉[smile=*]
regex = "\\[smiley=\\d+\\]";
title = title.replaceAll(regex, ""); //去掉[smiley=*]
regex = "\\[attachment\\]\\d+\\[/attachment\\]";
title = title.replaceAll(regex, ""); //去掉[attachment]*[/attachment]
List<String> images = new ArrayList<String>();
Pattern pat = Pattern.compile(regex);
Matcher matcher = pat.matcher(content);
while (matcher.find()) {
images.add(matcher.group(0));
}
上面的代码对不对?
谢谢大家
--
修改:darlingpeng FROM 221.204.231.*
FROM 221.204.231.*