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

  • SEARCH
  • Home
  • 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 9117913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:00:43+00:00 2026-06-17T05:00:43+00:00

I have this URL : http://www.exmaple.com/boo/a.php?a=jsd and what i want the output is something

  • 0

I have this URL :

http://www.exmaple.com/boo/a.php?a=jsd

and what i want the output is something like this :

http://www.exmaple.com/boo/

like wise if i have

http://www.exmaple.com/abc.html

it should be

http://www.exmaple.com/

and

http://www.exmaple.com/

should return

http://www.exmaple.com/

without any change

This is what i have tried

re.sub(r'\?[\S]+','',"http://www.exmaple.com/boo/a.php?a=jsd")

but it returns

http://www.exmaple.com/boo/a.php

Any suggestions what could be done to get the correct output or does anyone have any better ideas to get this done ?

  • 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-06-17T05:00:44+00:00Added an answer on June 17, 2026 at 5:00 am

    I would do something like that:

    >>> import re
    >>> url = "http://www.exmaple.com/boo/a.php?a=jsd"
    >>> url[:url.rfind("/")+1]
    'http://www.exmaple.com/boo/'
    

    To remove everything that is after the last “/”. I am not sure it covers all special cases though…

    EDIT: New solution using urlparse and my simple rfind:

    import re, urlparse
    def url_cutter(url):
        up = urlparse.urlparse(url)
        url2 = up[0]+"://"+up[1]+up[2]
        if url.rfind("/")>6:
                url2 = url2[:url2.rfind("/")+1]
        return url2
    

    Then:

    In [36]: url_cutter("http://www.exmaple.com/boo/a.php?a=jsd")
    Out[36]: 'http://www.exmaple.com/boo/'
    
    In [37]: url_cutter("http://www.exmaple.com/boo/a.php?a=jsd#dvt_on")
    Out[37]: 'http://www.exmaple.com/boo/'
    
    In [38]: url_cutter("http://www.exmaple.com")
    Out[38]: 'http://www.exmaple.com'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an url like this: http://www.w3schools.com/PHP/func_string_str_split.asp I want to split that url to
I have URL scheme for my blog like this: http://www.example.com/%YEAR%/%MONTH%/%CATEGORY%/%POST_TITLE%/ Now i want to
I have a url string like this: http://www.google.com/cse?cx=017840637368510444960:ny1lmky7r-0&client=google-csbe&output=xml_no_dtd&q=simon+g I need to send this url
I have this URL: http://www.example.com/prospective/deginfo.php?classname=PE&diploma_description=BSc+in+Mathematical+Sciences That I need to redirect to this URL instead:
Okay, let's say you have something like this: <span class=image style=background-image: url('http://www.example.com/images/image1.png')></span> Every CSS
I have a json like this: {result:{sandbox:1,0:{id:1106,url:http:\/\/www.example.com\/index1.html},1:{id:9655,url:http:\/\/www.example.com\/index2.html},2:{id:8447,url:http:\/\/www.example.com\/index3.html}}} and I'm retrieving it and then doing
Is this a valid http url http://www.example.com?x&y or we must always have = sign
i have this youtube url http://www.youtube.com/watch?v=9N51Etoikfw&feature=youtube_gdata i need to remove the feature parameter and
My goal is to have the url routing as following: http://www.abc.com/this-is-peter-page http://www.abc.com/this-is-john-page What is
Let's say I have a referral URL http://www.example.com/r?ref=86745348 and I want to completely hide

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.