RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find IPv4 Address match
Expression
(?:^|\s)([a-z]{3,6}(?=://))?(://)?((?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.(?:25[0-5]|2[0-4]\d|[01]?\d\d?))(?::(\d{2,5}))?(?:\s|$)
Description
Address match with optional match of protocol and port. Use case-insensitive. The matching brackets are: bracket 1 = optional protocol without :// -- bracket 3 = IPv4 address, with a more likely correct number range -- bracket 4 = optional port without : as an separator. Should work fine.
Matches
192.168.12.34 | 192.168.12.34:8080 | Link: https://202.133.76.34:80 | ftp://77.66.5.4
Non-Matches
262.133.76.34:80 | 262.133.76.34:1 | https:// 202.133.76.34:80 (matches not the protocol 'cos of the space)
Author Rating: Not yet rated. Gerry
Source
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Port can start with 0
Name: rtpHarry
Date: 10/28/2009 1:40:03 PM
Comment:
I just tested it and it lets the port start with a 0 such as :080 which is incorrect I think?


Copyright © 2001-2025, RegexAdvice.com | ASP.NET Tutorials