我正在使用正则表达式解析IP地址并提取其主机,端口,用户名和密码.
以下是我感兴趣的格式:
尝试这样的事情
(http://(\w+:\w+@)?)?(\d{1,3}\.){3}\d{1,3}(:\d{1,5})?
Run Code Online (Sandbox Code Playgroud)
说明:
(http://(\w+:\w+@)?)? - optional group of http:// followed by optional user:pass@
(\d{1,3}\.){3} - three groups of one to three digits followed by a dot
\d{1,3} - one to three digits
(:\d{1,5})? - optional group of colon followed by one to five digits
Run Code Online (Sandbox Code Playgroud)