Off Topic > Off Topic
Programming Megathread
Gytyyhgfffff:
/^((1[0-9][0-9]|[1-9][0-9]|[1-9])|2[0-4][0-9]|25[0-5])\.([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\.([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\.([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])$/
edit: it didn't work with php's preg_match, it does now
this absolute beast of regex will determine whether something is an ip address or not
it won't take in 0.0.0.0 as a valid one but anything from 1.0.0.0 to 255.255.255.255 it'll take
i absolutely hate regex because look at that its 100% unreadable but it is really good for doing a complex one-line thing like this which is neat
Becquerel:
--- Quote from: Gytyyhgfffff on April 12, 2016, 06:58:32 PM ---^((1[0-9][0-9]|[1-9]?[0-9])|2[0-4][0-9]|25[0-5])\.([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\.([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\.([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])$
this absolute beast of regex will determine whether something is an ip address or not
it won't take in 0.0.0.0 as a valid one but anything from 1.0.0.0 to 255.255.255.255 it'll take
i absolutely hate regex because look at that its 100% unreadable but it is really good for doing a complex one-line thing like this which is neat
--- End quote ---
i do not understand regex at all *shrug
BTW,I really should get started on that document i promised about the Concepts that Honno posted.
$trinick:
([0-9]{1,3}\.){3}[0-9]{1,3}
Gytyyhgfffff:
i don't understand regex at all either but https://regex101.com/ helped when i was testing it
the site includes an auto generated explanation of the thing which is useful when telling what different parts of the regex thing are
--- Quote from: $trinick on April 12, 2016, 07:02:41 PM ---([0-9]{1,3}\.){3}[0-9]{1,3}
--- End quote ---
ok you win (sort of)
it'll take 500.500.500.500 as a valid ip address which is definitely not a valid ip address
Becquerel:
--- Quote from: Gytyyhgfffff on April 12, 2016, 07:03:20 PM ---
it'll take 500.500.500.500 as a valid ip address which is definitely not a valid ip address
--- End quote ---
Yeah youre correct, IP addresses (atleast IPv4 ones, not sure about IPv6) cannot have their 4 octet divisions go above 255 since theyre 32 bit