V
V
Viktor Taran2021-09-14 18:01:24
Regular Expressions
Viktor Taran, 2021-09-14 18:01:24

What is the smallest regular expression for IP?

Daviche decided to see what the Internet says about this.
And to be honest, I was very disappointed, then real kilometer crutches do not pass all the validation.
In general, without thinking twice, I threw my own.
Is there any other way to reduce the size of the expression?
https://regex101.com/r/59OOQY/1
Condition:
Ipv4
exact match
inability to enter ip above 255
inability to enter any expression other than ip.
Exclude any left characters.
Minimum size.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vreitech, 2021-09-14
@shambler81

If we assume that the IP address must necessarily be from 4 numbers from 0 to 255, separated by three dots, then perhaps this:
^(1?\d{1,2}|2[0-4]\d|25[0-5])(\.(?1)){3}$

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question