【发布时间】:2018-05-15 12:16:55
【问题描述】:
所以我的字符串 url 是'http://helloworld.net/b/c/3?nw=174057&csid=fire.clan.com/gram/&din=&rand=52710&w=400&h=112'。这是在 python 2.7 中。
现在 url 中的参数 rand 一直在变化,并且始终是 5 个数字长度,因此它可以是 rand=12345 或 99999 等
现在我想在这种情况下将其 ('rand=52710') 更改为 'sub' 或只是 ''
我已经尝试过使用https://developers.google.com/edu/python/regular-expressions,但没有找到可靠的解决方案
任何帮助将不胜感激。
【问题讨论】:
-
@FHTMitchell 为什么我投了反对票?
-
哦,也许吧,但我做了几次尝试......我在这里阅读了
https://developers.google.com/edu/python/regular-expressions,并提出了match = re.search(r'rand=\d\d\d\d\d', url).group()的解决方案
标签: python regex string replace