Skip to main content
 首页 » 编程设计

python之正则表达式查找字符串中两个标记之间的位置

2025年05月04日21www_RR

我需要在两者之间找到任何东西

show_detail& 

和

;session_id=1445045 

在

https://www.site.gov.uk//search/cgi-bin/contract_search/contract_search.cgi?rm=show_detail&id=4035219;num=1;session_id=1445045;start=0 ;recs=20;subscription=1;value=0

在 python 中使用正则表达式。

我知道我需要使用 lookbehind/ahead 但我似乎无法让它工作!

请帮忙!

谢谢:)

请您参考如下方法:

为什么要使用正则表达式?

>>>> url = 'https://ww.site.gov.....' 
>>> start = url.index('show_detail&') + len('show_detail&') 
>>> end = url.index(';session_id=') 
>>> url[start:end] 
'id=4035219;num=1'