Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6138055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:48:10+00:00 2026-05-23T17:48:10+00:00

I have this python script which is supposed to wrap all that look like

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:48:10+00:00Added an answer on May 23, 2026 at 5:48 pm

    It depends a bit on which characters you allow in path names, but this does the trick for your example:

    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">Link to the file</a> HO HO HO'
    

    The [^ ] means anything but a space (the opposite of [ ]).

    If any character is allowed in a path name, it’s impossible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Python script that is running a few ls commands. This script
I have a python script which I would like to run at regular intervals.
I have a python script which looks like: if options.benchmark == 'perlbench': process =
I have a action.php script from where I call a python script like this:
I have a python script the runs this code: strpath = sudo svnadmin create
In a Python system for which I develop, we usually have this module structure.
I'm a newbie to python and the app engine. I have this code that
I have a python script which should parse a file and produce some output
I have a Python script which accepts a XML file as input and then
I have a Python script which uses the MySQLdb interface to load various CSV

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.