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

2024-05-14 21:01:34 发布

您现在位置:Python中文网/ 问答频道 /正文

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

209.127.191.180:9279:oexuirhs-dest:8rmd80fjmtmj45.95.96.132:8691:oexuirhs-dest:8rmd80fjmtmj193.8.56.119:9183:oexuirhs-dest:8rmd80fjmtmj45.95.99.226:7786:oexuirhs-dest:8rmd80fjmtmj45.95.99.20:7580:oexuirhs-dest:8rmd80fjmtmj

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

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

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


Tags: 文件ip密码代理port文章使用者知识产权
1条回答
网友
1楼 · 发布于 2024-05-14 21:01:34

以下是一个可能的解决方案:

(?<ip>((?<ipblock>[0-9]{1,3})\.){3}(?&ipblock)):(?<port>[0-9]+):(?<username>[a-z\-]+):(?<password>[a-zA-Z0-9]+)

此正则表达式包含每个信息的捕获组

IP:(?<ip>((?<ipblock>[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
)

端口:(?<port>[0-9]+)

用户名:(?<username>[a-z\-]+)

密码:(?<password>[a-zA-Z0-9]+)

username and password are really basic you probably need to extend it.

您可以在此处测试正则表达式:https://regex101.com/

This example: https://regex101.com/r/heWm1i/1

相关问题 更多 >

    热门问题