Here are three patterns that will allow you to capture valid IP addresses, valid Domains, and valid URLs anywhere in the text
See the demos below each pattern. Please let me know if there are any issues or any that are not correctly captured, I would be curious to know and resolve if I can. The code samples are Python, the regex flavor is Python and works with the re module.
IP ADDRESS:
The IP address pattern is x.x.x.x where x is a number between 0 and 255. The pattern below matches that IP address requirement:
ip_address_pattern = r"(?:(?<=^)|(?<=\s))((?:2[0-5][0-5]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\.(?:2[0-5][0-5]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3})(?=\s|$)"
IP address DEMO: https://regex101.com/r/hDYTV3/2
DOMAIN:
In the domain pattern are included the subdomain(s), domain and the top level domain (TLD):
domain_pattern = r"(?:(?<=^)|(?<=\s))(?:(?:ht|f)tps?://)?(?!\d+\.)((?:[^\W_]|-)[^\W_]*(?:-[^\W_]*)*(?:\.(?:[^\W_]|-)[^\W_]*(?:-[^\W_]*)*)*\.[^\W_][^\W_]*)(?:\s|$)"
DOMAIN DEMO: https://regex101.com/r/R4PZsf/10
URL:
url_pattern = r"(?:(?<=^)|(?<=\s))(?:(?:https?|ftp)://)?((?:[^\W_]|-)[^\W_]*(?:-[^\W_]*)*(?:\.(?:[^\W_]|-)[^\W_]*(?:-[^\W_]*)*)*\.[^\W_][^\W_]*)(?::\d+)?/(?:[\w~_.:/?#\[\]@!$&'*+,;=()-]*(?:(?:%[0-9a-fA-F][0-9a-fA-F])+[\w~_.:/?#\[\]@!$&'*+,;=()-]*)*)?(?=\s|$)"
# Accepted Characters in the path:
uri_chars = r"[\w~_.:/?#\[\]@!$&'*+,;=()-]"
# Percentage must be followed by two hexadecimal characters
percent_encoding_pattern = r"%[0-9a-fA-F][0-9a-fA-F]"
URL DEMO: https://regex101.com/r/UhhGZU/4