RegEx - 匹配可变长度的数字 [英] RegEx - Match Numbers of Variable Length

查看:40
本文介绍了RegEx - 匹配可变长度的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解析一个到处都是参考编号的文档.

I'm trying to parse a document that has reference numbers littered throughout it.

Text text text {4:2} 更多令人难以置信的 text {4:3} 稍后{222:115} 还有一些文字.

Text text text {4:2} more incredible text {4:3} much later on {222:115} and yet some more text.

引用总是用方括号括起来,并且两者之间总是有一个冒号.我写了一个表达式来找到它们.

The references will always be wrapped in brackets, and there will always be a colon between the two. I wrote an expression to find them.

{[0-9]:[0-9]}

但是,当您遇到一个两位或三位数字时,这显然会失败,而且我无法弄清楚应该是什么.永远不会超过 3 位数字 {999:999} 是要处理的最大大小.

However, this obviously fails the moment you come across a two or three digit number, and I'm having trouble figuring out what that should be. There won't ever be more than 3 digits {999:999} is the maximum size to deal with.

有人知道处理这个问题的正确表达吗?

Anybody have an idea of a proper expression for handling this?

推荐答案

{[0-9]+:[0-9]+}

尝试添加加号

这篇关于RegEx - 匹配可变长度的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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