正则表达式重用模式来捕获多个组? [英] Regex reuse a pattern to capture multiple groups?

查看:797
本文介绍了正则表达式重用模式来捕获多个组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想多次匹配一些模式,完全像描述这里

I would like to match some pattern multiple times, exactly like described here.

^(somelongpattern[0-9])([,; ]+(?1))*$

这将匹配例如:

somelongpattern0
somelongpattern9 ,; somelongpattern2

但是上面的代码在pcre中工作,它在java中不起作用。它给我一个错误未关闭的选项组(?1)

However above code works in pcre, it does not work not in java. It gives me an error "unclosed options group" on (?1)

有什么方法可以做到这一点吗?我有一个非常长的正则表达式模式,如果可能的话我不想重复2次。

Is there any way how to do this? I have a very long regex pattern and i don't want to repeat it 2 times if possible.

推荐答案

在审查Java时他们仍然没有遵循子程序的PCRE指南。基本上Java Regex不支持子例程。

In reviewing the Java documentation they still do not follow the PCRE guidelines for subroutines. Basically Java Regex does not support subroutines.

另见 Java Regex手册

这篇关于正则表达式重用模式来捕获多个组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆