我有一个很大的String,其中包含一些标记,例如:
{codecitation class="brush: java; gutter: true;" width="700px"}
我需要收集长字符串中包含的所有标记。我在此任务中发现的困难是所有标记都包含不同的参数值。他们唯一的共同点是初始部分:
{codecitation class="brush: [VARIABLE PART] }
您是否有使用正则表达式收集Java中所有标记的建议?
使用模式匹配找到标记,如下所示。我希望这将有所帮助。
String xmlString = "{codecitation class=\"brush: java; gutter: true;\" width=\"700px\"}efasf{codecitation class=\"brush: java; gutter: true;\" width=\"700px\"}";
Pattern pattern = Pattern.compile("(\\{codecitation)([0-9 a-z A-Z \":;=]{0,})(\\})");
Matcher matcher = pattern.matcher(xmlString);
while (matcher.find()) {
System.out.println(matcher.group());
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句