[英]multiple groups with the same name regex java?
是否有任何 Java 正则表达式 api 或库可以在一种模式中接受多个具有相同名称的组?
This is a very old question, but google brought me here, I found a solution for PHP using the /J
modifier.这是一个非常古老的问题,但谷歌把我带到了这里,我找到了一个使用
/J
修饰符的PHP解决方案。 All details explained here: http://www.rexegg.com/regex-capture.html#dupe_names所有细节在这里解释: 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.
在 .NET、PCRE(C、PHP、R...)、Perl 和 Ruby 中,您可以在模式的不同位置使用相同的组名。 (In PCRE you need to use the (?J) modifier or PCRE_DUPNAMES option.) In these engines, this regex would be valid:
(在 PCRE 中,您需要使用 (?J) 修饰符或 PCRE_DUPNAMES 选项。)在这些引擎中,此正则表达式将是有效的:
:(?<token>\d+)|(?<token>\d+)#
Working example here https://regex101.com/r/h7HJXj/1这里的工作示例https://regex101.com/r/h7HJXj/1
alternative of (ab(?<a>[\\w]*)|bs(?<a>[\\w]*))
regex is (ab|bs)(?<a>[\\w]*)
with same name. (ab(?<a>[\\w]*)|bs(?<a>[\\w]*))
正则表达式的替代是(ab|bs)(?<a>[\\w]*)
同名. check test in the demo link with (ab(?<a>[\\w]*)|bs(?<b>[\\w]*))
and (ab|bs)(?<a>[\\w]*)
.使用
(ab(?<a>[\\w]*)|bs(?<b>[\\w]*))
和(ab|bs)(?<a>[\\w]*)
在演示链接中检查测试(ab|bs)(?<a>[\\w]*)
. these gives you same result.这些给你同样的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.