I\'m trying to parse a document that has reference numbers littered throughout it.
Text text text {4:2} more incredible text {4:3} much later on {22
{[0-9]+:[0-9]+}
try adding plus(es)
You can specify how many times you want the previous item to match by using {min,max}
.
{[0-9]{1,3}:[0-9]{1,3}}
Also, you can use \d
for digits instead of [0-9]
for most regex flavors:
{\d{1,3}:\d{1,3}}
You may also want to consider escaping the outer {
and }
, just to make it clear that they are not part of a repetition definition.
Try this:
{[0-9]{1,3}:[0-9]{1,3}}
The {1,3}
means "match between 1 and 3 of the preceding characters".
What regex engine are you using? Most of them will support the following expression:
\{\d+:\d+\}
The \d
is actually shorthand for [0-9]
, but the important part is the addition of +
which means "one or more".