Consider a pair of IPv4
or IPv6
address and port, separated by either /
or :
, e.g.
10.10.10.10:1234
The port is optional, so strings like
10.10.10.10/
10.10.10.10:
10.10.10.10
are also valid. The address/port pair may be followed by space or comma characters and it is part of a much longer enclosing string.
What would be a very simple regex to extract the 2 values in separate fields from the enclosing string (without using String manipulation functions)?
For example, an expression like
(?<address>[^\s,]+[^\s,:\.])((/|:)(?<port>\d*))?
extracts both address and port in the same string.
The goal here is to achieve extraction with the simplest possible regex, even if it is not 100% accurate (i.e., even if it matches other strings as well).