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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:58:34+00:00 2026-06-12T09:58:34+00:00

Using Regular Expressions I want to extract all links to files or images contained

  • 0

Using Regular Expressions I want to extract all links to files or images contained inside some HTML text. Tried several examples but they failed for many reasons (being the main that I’m not skilled at regular expressions 🙂 )

1) First I’ve tried this:

> Regex("<img[^>]+src=[""']([^""']+)[""']", RegexOptions.Singleline Or
> RegexOptions.IgnoreCase)

(It works OK for images)

2) And then this:

Regex("href=[""']([^""']+)[""']", RegexOptions.Singleline Or RegexOptions.IgnoreCase)

1) extracts all images, it works OK but thats only a partial solution.
2) extracts all href=”asdf”, but I want to extract only the href pointing to files, I dont want anchors (#middlesection) or .aspx or even url without extensions like href=”www.google.com/site”

I want to know how can I extract all files from a given text, being a file any link that ends with a dot and three characters 🙂

I’m not interested in “.aspx” or “.html”, neither in extensionless urls like “id_content=99”, nor anchors like “#anchor123”.

Is it possible to pack this into one single RegExp? The idea behind all this is that I have to copy every single files referenced in some HTML from one place to another, thus I need an ArrayList containing only the file paths to copy.

Thanks in advance!

Added some sample code just to clarify that is not about “in the wild” html

Giving this code:

<p>This is a paragraph</p>
<br>
<a href="#someplace">Go to someplace</a>
<ul>
    <li><p><a href="../files/document.pdf">Important PDF 1</a></p></li>
    <li><p><a href="../files/document.xls">Important XLS</a></p></li>
</ul>
<a href="content.aspx?id_content=55">Go to content 55</a>
<br>
<img src="../images/nicelogo.jpg">

I want to get this:

"../files/document.pdf"
"../files/document.xls"
"../images/nicelogo.jpg"

I DONT want to get this:

"#someplace"
"content.aspx?id_content=55"

Thats it, with the reg exp that I have, I get all the links, I ONLY want the ones that represents a file. The HTML is written by hand by me (long story) so there will be no strange double-double quotes or malformed tags or strange chars.

I know its possible to do because its almost done, I just dont know how to tell “give me only the matches that have “.something” at the end being “something” a three chars long string”. Am I clear? 🙂

  • 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-12T09:58:35+00:00Added an answer on June 12, 2026 at 9:58 am

    Something like this should work:

    <a href=\"(.*\.[a-z0-9]{3})\"
    

    but if it does, you have to promise me that you will come back and comment here when you regret that you used regex for this.

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

Sidebar

Related Questions

I want to extract text from a column using regular expressions in Oracle 11g.
I want to extract abc from images/abc.png using Javascript Regular experssion in one line.
Using PHP Regular Expression I want to extract some value from code <?xml version=1.0
Using PHP PCRE regular expressions I want to extract the centre part of a
I'd like to extract the text from an HTML file using Python. I want
I'd like to extract the text from an HTML file using Python. I want
I want to validate mathematical expressions using regular expression. The mathematical expression can be
If I want to analyze a string using dozens of regular-expressions, could either the
I want to be able to detect (using regular expressions) if a string contains
I'm trying to extract only certain elements of a string using regular expressions and

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.