I'm looking to match numbers that are either 1 or 2 digit (but not more) long so I can add leading zeroes. My input strings look like these:
LL.1 ETX 189 1.20.3.4[8] 1.30.4[17] 229.c.85.8[4] 62.c.80.11 RR 60 H 2 R.60 H 2 Y.11.25[28] Abc T.14.55 LL 108 ETX 189 Content 1364 With the application of the regex I would hope to identify the following:
LL.1 ETX 189 => match: 1 1.20.300.4[8] => match: 1, 20, 4, 8 1.30.4[17] => match: 1, 30, 4, 17 229.c.85.8[4] => match: 85,8,4 62.c.80.11 => match: 62, 80, 11 RR 60 H 2 => match: 60, 2 R.60 H 2 => match: 60, 2 Y.11.25[28] => match: 11, 25, 28 Abc T.14.55 => match: 14, 55 Whilst ignoring:
LL 108 ETX 189 Content 1364 I thought doing something as simple as: ([1-90-9]{1,2}) would work but this returns the following:
LL.1 ETX 189 => match: 1, 18, 9 1.20.300.4[8] => match: 1, 20, 30, 0, 4, 8 1.30.4[17] => match: 1, 30, 4, 17 229.c.85.8[4] => match: 22, 9, 85,8,4 62.c.80.11 => match: 62, 80, 11 RR 60 H 2 => match: 60, 2 R.60 H 2 => match: 60, 2 Y.11.25[28] => match: 11, 25, 28 Abc T.14.55 => match: 14, 55 LL 108 ETX 189 => match: 10, 8, 18, 9 Content 1364 => match: 13, 64 Any suggestions on how I can achieve this?
I've had a look at this question: 'RegEx Expression /w limited length and chars' and this one: Regex match one digit or two..
[1-90-9]is equivalent to[0-9](?<!\d)\d{1,2}(?!\d), demo.\dinclude more characters than[0-9]?/uflag.