10

Python 正则的问题 - V2EX

 3 years ago
source link: https://www.v2ex.com/t/801288
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  Python

Python 正则的问题

  Vvvteran · 20 小时 30 分钟前 · 120 次点击
环境:py3.9.6
部分代码:
ip = '1.2.3.4:8080/3xx3/a.php?b=1'
parse_obj = urlparse(ip)
print(parse_obj)

解析之后的结果:
ParseResult(scheme='1.2.3.4', netloc='', path='8080/3xx3/a.php', params='', query='b=1', fragment='')

请问各位大佬,针对这种不带 http(s)://的情况,如何使用正则提取 path 中的端口而不要之后路径呢,小白求解。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK