Srle
Srle

Reputation: 10496

regex, match private ipV4 starting with 10 with optional subnet

Trying to match any private ipV4 address that start with 10 and optionally ends with CIDR notation omitting default gateway, such as:

10.123.123.123 match
10.12.123.1 do not match because it ends with .1 => default gateway
10.12.123.2 match
10.123.123.123/23 match

What i have for now is matching private ip address that start with 10
'10\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' which will allow default gateway and will not match CIDR

Upvotes: 0

Views: 289

Answers (1)

dawg
dawg

Reputation: 103864

Try:

\b(10\.\d{1,3}\.\d{1,3}\.(?:[2-9]|\d{2,3})(?:\/\d\d)?)

Demo

Upvotes: 1

Related Questions