gpt4 book ai didi

java - 具有相同名称的正则表达式 java 的多个组?

转载 作者:搜寻专家 更新时间:2023-10-31 20:20:44 28 4
gpt4 key购买 nike

是否有任何适用于 java 的正则表达式 api 或库可以在一个模式中接受具有相同名称的多个组?

最佳答案

这是一个非常古老的问题,但是谷歌把我带到这里,我找到了一个使用 /J 修饰符的 PHP 解决方案。此处解释了所有详细信息:http://www.rexegg.com/regex-capture.html#dupe_names

In .NET, PCRE (C, PHP, R…), Perl and Ruby, you can use the same group name at various places in your pattern. (In PCRE you need to use the (?J) modifier or PCRE_DUPNAMES option.) In these engines, this regex would be valid:

:(?<token>\d+)|(?<token>\d+)#

工作示例在这里 https://regex101.com/r/h7HJXj/1

关于java - 具有相同名称的正则表达式 java 的多个组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20724324/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com