I have this python script which is supposed to wrap all that look like a path within a tag to make an url out of it.
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
And I tried many combination like this one :
>>> 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>'
But it seems I’m not able to get it right. So I could use a little help there !
Thanks in advance
It depends a bit on which characters you allow in path names, but this does the trick for your example:
The [^ ] means anything but a space (the opposite of [ ]).
If any character is allowed in a path name, it’s impossible.