这是我现在的设置:
private static Pattern bbCodePattern;
private static Matcher patternMatcher;
private static final String BB_GENERIC = "\\[(.*)\\](.*?)\\[\\/(.*)\\]";
...
public static List<PostComponent> process(final String bbCode) {
List<PostComponent> postComponents = new ArrayList<>();
patternMatcher = bbCodePattern.matcher(bbCode);
while(patternMatcher.find()) {
postComponents.add(new PostComponent(patternMatcher.group(2), getComponentType(patternMatcher.group(1))));
}
return postComponents;
}
...
当bbCode
为[img]https://forum.com/image.png[/img] [spoiler]texttohide[/spoiler]
时,返回的列表只有1个值,而如果是[img]https://forum.com/image.png[/img]\n[spoiler]texttohide[/spoiler]
,则返回的列表具有预期的2个元素。是什么导致了这种行为?