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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:39:19+00:00 2026-06-14T04:39:19+00:00

I am trying to write a simple javascript function to pull just img urls

  • 0

I am trying to write a simple javascript function to pull just img urls out of text.

i have nearly got it working but i am having a issue with params how can i remove them and also returning the full img url, could someone help not the best at regexs

document.write(getImagesInText("Whether the view should  hidden from (i.e., ignored by) the accessibility service. http://jsfiddle.net/ http://thickbox.net/images/plant4.jpg afhttp://thickbox.net/images/plant4.jpg?4t34t34t"));


function getImagesInText(text){

        var html = text;
        var urlRegex = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)+\.(?:jpg|jpeg|gif|png)/gi;
        return html.replace(urlRegex, '<img src="$1" width="48" height="48"/>');

}

view the example here.
http://jsfiddle.net/7dJCm/1/

UPDATE

function getImagesInText( s ) {
    var html = s;
    var imgregex = /((http(s)?|ftp):\/\/[\S]*(\.jpg|.jpeg|\.gif|.png)[\S]*)/gi;
    var urlRegex = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;

    html = html.replace(/(\.jpg|\.jpeg|\.gif|\.png)/gi, function( ext ) { return ext + " "; }); 

    html = html.replace(/(http|https)/gi, function( ext ) { return " " + ext; });

    html = html.replace(urlRegex, function( path ) {
           if(path.match(/jpg|png|gif|jpeg/g)){
             return "<img width='48' height='48' src='" + path + "' />";
           }else{
             return "<a href='" + path + "'>" + path + "</a>";
           }
    });

    return html;
}

http://jsfiddle.net/7dJCm/16/

  • 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-14T04:39:20+00:00Added an answer on June 14, 2026 at 4:39 am
    var s = "Whether the view should  hidden from (i.e., ignored by) the accessibility service. http://jsfiddle.net/ http://thickbox.net/images/plant4.jpg afhttp://thickbox.net/images/plant4.jpg?4t34t34t";
    
    console.log( getImagesInText(s) ) // "Whether the view should  hidden from (i.e., ignored by) the accessibility service. http://jsfiddle.net/ <img src='http://thickbox.net/images/plant4.jpg' /> af<img src='http://thickbox.net/images/plant4.jpg?4t34t34t' />"
    
    function getImagesInText( s ) {
        var regex = /((http(s)?|ftp):\/\/[\S]*(\.jpg|\.jpeg|\.gif|\.png)[\S]*)/gi;
    
        return s.replace(regex, function( path ) {
            return "<img src='" + path + "' />";
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a simple Javascript(jQuery) function that randomly displays 6 Divs out
I am trying to write a simple script in JavaScript, just for testing purposes.
I am trying to write a simple decrypt function in JavaScript that would take
I'm trying to write a simple JavaScript function to remove all occurrences of a
I'm trying to write a simple javascript function that will clone some html input
I'm new to Javascript and was trying to write a simple function prototype for
I trying to write a simple function to call unmanaged code from managed code.
I am trying to write some simple code which will read a text file
I am trying to write a simple Java function that will take a list
I am trying to write a simple if statement in javascript (jquery library) that

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.