有没有办法只获得独特的匹配?在匹配后不使用列表或地图,我希望匹配器输出立即是唯一的。
样本输入/输出:
String input = "This is a question from [userName] about finding unique regex matches for [inputString] without using any lists or maps. -[userName].";
Pattern pattern = Pattern.compile("\\[[^\\[\\]]*\\]");
Matcher matcher = pattern.matcher(rawText);
while (matcher.find()) {
String tokenName = matcher.group(0);
System.out.println(tokenName);
}
这将输出以下内容:
[userName]
[inputString]
[userName]
但我希望它输出以下内容:
[userName]
[inputString]