我有這個python腳本,它應該包裝所有看起來像標籤內的路徑,使一個URL脫離它。將路徑轉換爲URL的正則表達式
def wrap(text, regex):
start, end = '<a href="/static', '">Link to the file</a>'
matchs = sorted([(s.start(), s.end()) for s in re.finditer(regex, text)],
reverse = True)
for match in matchs:
text = text[:match[1]] + end + text[match[1]:]
text = text[:match[0]] + start + text[match[0]:]
return text
我嘗試了許多組合像這樣的:
>>> wrap('HA HA HA /services/nfs_qa/log.lol HO HO HO', '/services/nfs_qa/.* ??')
'HA HA HA <a href="/static/services/nfs_qa/log.lol HO HO HO">Link to the file</a>'
但似乎我不能得到它的權利。所以我可以在那裏使用一點幫助!
在此先感謝
謝謝!我應該再次搜索python re doc,我想。我會找到這樣的事情。 – jaes