I am trying to have my regex match the following:
169.254.0.0-169.254.254.255
Could anyone please help how can I achieve this.
so far I have this:
169\.254\.([1-9]{1,2}|[1-9]{1,2}[1-4])
but it would also pick up 169.254.255.1 which should not be one of the matches.
Please help!
thanks
I've written an article that provides regular expressions for all the components of a generic URI (as defined in RFC3986: Uniform Resource Identifier (URI): Generic Syntax)
See: Regular Expression URI Validation
One of the components of a generic URI is an IPv4 address. Here is the free-spacing mode Python version from that article:
And the un-commented JavaScript version:
This is the regex I use for general IP validation:
Breakdown:
This hasn't failed my yet for IP address validation.
For your specific case, this should do it:
This is very long because I couldn't figure out how to get 169.254.(0-254).255 to check without getting 169.254.255.1 to fail
Edit: Fixed due to comments
the regex
([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4])
matches 0-254.see this page for more discussion