将代理拆分为IP:PORT:USER:PASS(Python)

将代理拆分为IP:PORT:USER:PASS(Python),python,proxies,Python,Proxies,因此,我的代理文件如下所示: 209.127.191.180:9279:oexuirhs dest:8rmd80fjmtmj 45.95.96.132:8691:oexuirhs dest:8rmd80fjmtmj 193.8.56.119:9183:oexuirhs dest:8rmd80fjmtmj 45.95.99.226:7786:oexuirhs dest:8rmd80fjmtmj 45.95.99.20:7580:oexuirhs dest:8rmd80fjmtmj 我想将其拆分为I

因此,我的代理文件如下所示:

209.127.191.180:9279:oexuirhs dest:8rmd80fjmtmj
45.95.96.132:8691:oexuirhs dest:8rmd80fjmtmj
193.8.56.119:9183:oexuirhs dest:8rmd80fjmtmj
45.95.99.226:7786:oexuirhs dest:8rmd80fjmtmj
45.95.99.20:7580:oexuirhs dest:8rmd80fjmtmj

我想将其拆分为IP:PORT:USER:PASS 我曾想过使用正则表达式,但我想不出来我希望它是一个变量,以后可以使用,例如:

知识产权= 港口= 使用者= 通过=

当然,这是假设代理和用户名/密码每次都不同
thx已用于阅读此文章。

这里有一个可能的解决方案:

(?<ip>((?<ipblock>[0-9]{1,3})\.){3}(?&ipblock)):(?<port>[0-9]+):(?<username>[a-z\-]+):(?<password>[a-zA-Z0-9]+)
((([0-9]{1,3}){3}(?&ipblock)):([0-9]+):([a-z\-]+):([a-zA-Z0-9]+)
此正则表达式包含每个信息的捕获组

IP:
((([0-9]{1,3})\.{3}(?&ipblock))

IP Matchgroup解释道:

(?<ip>                <-- the named group
  (
    (?<ipblock>{1,3}) <-- matches numbers 0 - 999
    \.                <-- ip dot
  ){3}                <-- repeats the whole group three times
  (?&ipblock)         <-- reuses the ipblock match group because of the dot
)
(?