0

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..

5
  • [1-90-9] is equivalent to [0-9] Commented Jul 15, 2021 at 10:57
  • 2
    (?<!\d)\d{1,2}(?!\d), demo. Commented Jul 15, 2021 at 10:57
  • @WiktorStribiżew doesn't \d include more characters than [0-9]? Commented Jul 15, 2021 at 10:58
  • No, unless you add the /u flag. Commented Jul 15, 2021 at 10:59
  • @Cid - :-) showing my ignorance when it comes to regex Commented Jul 15, 2021 at 11:08

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.