.NET Framework Bookmark and Share   
 index > Regular Expressions > Regular Expression for URL / IP with Port Number
 

Regular Expression for URL / IP with Port Number

Hi,

I need to validate (URL or IP) with port number, please give me a good regular expression for this

Examples:

http://10.25.144.25:1020

http://10.25.15.254

https://www.domain.suffix:1250

http://www.domain.suffix

https://www.domain.suffix

https://domain.suffix


Thanks in advance,

Praneeth Avula.
Praneeth Avula
A regex to validate all of that can become pretty involved if you require validation of TLD's, IP addresses, of RFC standards and such. The following will only really attempt to prevent invalid characters in the domain/ip and ensure a valid port if provided:

boolfoundMatch=Regex.IsMatch(SubjectString,@"(?:https?|ftp)://[-a-zA-Z0-9.]+(:(6553[0-5]|655[0-2][0-9]|65[0-4][0-9][0-9]|6[0-4][0-9][0-9][0-9]|\d{2,4}|[1-9]))?");
inetscan

You can use google to search for other answers

Custom Search

More Threads

• Regex.IsMatch rookie question..
• help with regex
• Regex for blank spaces only.
• Regular expression to find the difference
• Tricky Regular expression
• extracting data from html
• Return *only* unique matches?
• Excluding specific matches from a general pattern
• Request help for a simple Regular expression
• regexes with balancing group definition