我想在java中匹配特定文本的正则表达式模式。在匹配时,我需要以相反的顺序查找匹配项。
示例:
Regex Pattern -- [([^]]*])
Input String -- [blue][red][green]
Output -- 1st match --->[blue]
2nd match --->[red]
3rd match --->[green]
但我希望匹配顺序相反。
Expected output -- 1st match --->[green]
2nd match --->[red]
3rd match --->[blue]
请帮助如何形成正则表达式以实现预期的输出。
最佳答案
假设您已遵守正则表达式日期”
ArrayList<String> strings = new ArrayList<>();
Matcher foo = date.matcher("foo");
while (foo.matches()) {
strings.add(foo.group());
}
Collections.reverse(strings);
关于java正则表达式反向匹配循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39737067/