简体   繁体   中英

Regular expressions for proxy pattern

From the list of text junk I'm using regular expression. The following will do that job to parse proxy pattern
(\\d{1,3}\\.){3}\\d{1,3}:\\d{2,5} . But This pattern parse the text like this:

692.248.222.879:43780
692.83.47.579:43780

Which is not possible IP address. I want to know, how to skip this kind of ranges using regular expressions?

Tools I prefer: Java or C#, notepad++. However any languages will do.

try this:

\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]?)\b:\d{2,5}

'

692.248.222.879:43780 
692.83.47.579:43780
192.168.1.1:27052

works with the last one only

To validate numeric ranges with regular expressions, you have to supply every possible combination, which is why it's usually best to use built-in tools, like .NET's IPAddress.TryParse . But anyway...

((?:1?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:1?\d{1,2}|2[0-4]\d|25[0-5]):\d{2,5}
"^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$:\d{2,5}";

证明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM