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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:46:50+00:00 2026-06-17T16:46:50+00:00

I search to detect in a string if the content is just a text

  • 0

I search to detect in a string if the content is just a text or if it’s an image URL. I base my detection with the filetype, but I don’t know how to detect multiple file types…

var wrapper = (content.indexOf(".jpg", ".jpeg", ".gif", ".png", ".bmp") != -1)
                ? '<img src="' + content + '" />'
                : '<span>' + content + '</span>';

I know this syntax for indexOf is wrong, but in an ideal, that’s what I search!

  • 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-17T16:46:50+00:00Added an answer on June 17, 2026 at 4:46 pm

    I would go with a cleaner solution – no slice/indexOf or anything like that involved: It tests all elements of the ext array against the content and returns the elements, which match. Since there should be only one match, you just need to check the first element.

    var content = "/test.png",
        ext = [".jpg", ".jpeg", ".gif", ".png", ".bmp"],
        res,wrapper;
    
    res = ext.filter(function(el){return content.match(el)});
    
    wrapper = res[0] ? '<img src="'+content+'" />' : '<span>'+content+'</span>';
    

    See Array.prototype.filter on MDN for more explanation. As with Fabrizio’s solution this solution might break too, if you have filenames with several . /test.png.jpg (whatever the reason for that might be).

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

Sidebar

Related Questions

This question is nearly identicle to : Php search string (with wildcards) , but
What's a reliable way to detect if the Google search URL is from an
Typical search layout having RelativeLayout, TextView, EditText and Button I have a.9.png image having
A search procedure using full text search (it means: is hard to reproduce the
A search api is returning me some meta data along with a URL eventURL.
A search API is returning date in String format,I want to compare that date
How can I search a NSString for a url in Xcode iOS? For instance,
I need to detect search engines that refers to my website. Since every search
I have a jquery search suggestions. The function is running ok. But now I
Quick search revealed many guides explaining how to detect an iPhone or iPad: RewriteEngine

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.