我有以下字符串
52x10x20x30x40
字符串可以扩展,但具有相同的模式,并且其两侧都会有其他字符串:例如
"Hello something 52x10x20x30x40 bla bla bla"
我想捕获所有 2 位数字。
我有以下正则表达式
Pattern.compile("(\\d\\d)([x]\\d\\d)+");
但是使用这个正则表达式我只能得到以下组:
1: 52
2: x40
最佳答案
为什么不简单地:
"52x10x20x30x40".split("x");
?
Forgot to mention that there can be other strings on both sides.
您可以搜索 "\\d{2}(x\\d{2})+"
,然后使用 split("x")
匹配。
关于Java 模式重复捕获组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9520525/