I'm creating a small IP:PORT scraper in PHP. The problem is that I'm pretty unfamiliar with RegEx.
So I've been piecing together what I can.
Here's what I've got:
/\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?):([0-9]{1,5})\b/
I know this isn't the best. At least not the end to grab the port, because it means that ports will be able to be things like 99999.
Also, it seems to return two matches this way. The IP:PORT and the PORT. I just need it to grab the full IP:PORT, not one or the other.
I've posted a regular expression below what matches either ip or ip and port.
FailedDev's Port portion of his answer - shortened it a bit and set boundaries, this will only catch the port
Your regex is fine so I will just concentrate on the port itself. This regex :
Will optionally catch any valid port number and store it to named group port.
Note: free spacing must be enabled:
You could try this:
There are a few examples for IP matching here. Just take any of them and put
:\d{1,5}\b
on the end (to match a port).I have used this long time ago.