user2924482 user2924482 - 22 days ago 11
Swift Question

Swift:Regular expression to detect IP address in string

I'trying to detect if IP address is inside of string for example:

"home 10.10.10.12:443 is connected"

Any of you knows if is regular expression I can use to detect the ip and modify the ip?

I'll really appreciate your help

Answer

You can try this regex:

\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}

Demo: https://regex101.com/r/DLkR37/3

Then, check out this question to learn how to use this Regex in Swift to modify the current ip to a different one:

Swift replace substring regex