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 8458839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:11:13+00:00 2026-06-10T13:11:13+00:00

The problem i’m facing is badly named links… There are few hundred bad links

  • 0

The problem i’m facing is badly named links…
There are few hundred bad links in different files.

So I write bash to replace links

<a href="../../../external.html?link=http://www.twitter.com">
<a href="../../external.html?link=http://www.facebook.com/pages/somepage/">

<a href="../external.html?link=http://www.tumblr.com/">
to direct links like
<a href="http://www.twitter.com>

I know we have pattern ../ repeating one or more times. Also external.html?link which also should be removed.

How would recommend to do this? awk, sed, maybe python??
Will i need regex?

Thanks for opinions…

  • 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-10T13:11:15+00:00Added an answer on June 10, 2026 at 1:11 pm

    This could be a place where regular expressions are the correct solution. You are only searching for text in attributes, and the contents are regular, fitting a pattern.

    The following python regular expression would locate these links for you:

    r'href="((?:\.\./)+external\.html\?link=)([^"]+)"'
    

    The pattern we look for is something inside a href="" chunk of text, where that ‘something’ starts with one or more instances of ../, followed by external.html?link=, then followed with any text that does not contain a " quote.

    The matched text after the equals sign is grouped in group 2 for easy retrieval, group 1 holds the ../../external.html?link= part.

    If all you want to do is remove the ../../external.html?link= part altogether (so the links point directly to the endpoint instead of going via the redirect page), leave off the first group and do a simple .sub() on your HTML files:

    import re
    redirects = re.compile(r'href="(?:\.\./)+external\.html\?link=([^"]+)"')
    
    # ...
    redirects.sub(r'href="\1"', somehtmlstring)
    

    Note that this could also match any body text (so outside HTML tags), this is not a HTML-aware solution. Chances are there is no such body text though. But if there is, you’ll need a full-blown HTML parser like BeautifulSoup or lxml instead.

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

Sidebar

Related Questions

Problem PHP session in different folder. I have problem with PHP session. There are
Problem is like this: Suppose there are records in dataTable with FruitType as A
Problem is like this: I have two winapi application's. There is only one way
Problem: I have two spreadsheets that each serve different purposes but contain one particular
Problem (simplified to make things clearer): 1. there is one statically-linked static.lib that has
Problem is described and demonstrated on the following links: Paul Stovell WPF: Blurry Text
Problem description I have 6 databases from 6 different machines, and having one cloud
Problem: I'm working on a website where there is a dial that displays a
I've tracked down a weird MySQL problem to the two different ways I was
Problem: to combine PATHs with filenames, such that I can easily source many files.

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.