Posts: 4,647
Threads: 1,494
Joined: Sep 2016
actually, this would be better as a function. given a string, find the first valid IPv4 or IPv6 address in the string, returning a 2-tuple of the slice of the string the address is at.
find_ip_address('foo8.8.4.4bar') -> (3,10)
find_ip_address('myIPaddress') -> None
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
that could be a useful enough start if it also did ipv6.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
holy **** !!!!
those are
very complex expressions. i think i will avoid those for now. i would have
no chance dealing with any bugs. i am still a noob at REs of any basis.
my brain already hurts just looking at that.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
one idea is to step through the string and run a validate at each position until a positive result. then the next issue is the length or end position. but if the use case is to know whether or not the string has and address, such as doing a grep for an ip address, this would be enough.
one way to check for length after the starting position is found is to increment the length as the validation test is done and use the previous value when a failure is hit if the longest address is wanted. if the shortest is wanted, such as 1.1.1.1 when 1.1.1.123 is there, just return at the first positive.
validation could be done by
socket.inet_pton() with the appropriate address family flags.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.