java正则表达式反向匹配循环

标签 java regex

我想在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/

相关文章:

java - 将 Jersey 客户端 1.x 升级到 2.x 时 UriBuilder 上的 AbstractMethodError

java - 从 Eclipse 项目创建批处理文件

javascript - 如何从 Javascript 中的字符串中获取占位符?

python - 查找与需要从另一个列表中有序包含的正则表达式匹配的字符串子列表

regex - Notepad++ 替换文本内的新行

javascript - 搜索字符串并捕获特定 HTML 属性的值

java - JPA EmptyResultDataAccessException 处理

java - 在 Maven 生成源或 Maven 安装期间删除文件夹

java - 字符串比较,字母顺序

REGEX - 如何在文件名中查找两个连字符?