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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:57:09+00:00 2026-05-27T16:57:09+00:00

I am getting output from a FB page notes using the Facebook API. In

  • 0

I am getting output from a FB page notes using the Facebook API. In some notes there is an image and in others there are not. I want to extract the src of the image if it is there.

I am using this regex and it works fine, but the problem is that if a note does not contain an image all fails.

json.data[i].message.match(/src=(.+?[\.jpg|\.gif|\.png]")/)[1]

Can I use some kind of a control structure (if else) to check if a note contains an image before using the regex?

If the note does not contain an image I get this error:

Result of expression 'json.data[i].message.match(/src=(.+?[\\.jpg|\\.gif|\\.png]\")/)' [null] is not an object.

I am using Javascript and Appcelerator.

  • 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-05-27T16:57:10+00:00Added an answer on May 27, 2026 at 4:57 pm

    Can I use some kind of a control structure (if else) to check if a note contains an image before using the regex?

    Yes to the control structure, but you don’t need to do it before the regex, the regex tells you whether it’s successful. Break your statement into two parts:

    var result = json.data[i].message.match(/src=(.+?[\.jpg|\.gif|\.png]")/);
    if (result) {
        path = result[1];
    }
    

    The problem you’re having is that match returns null when there’s no match, but then you’re trying to treat it like an object by applying [1] to it — causing an error. By getting the result and making sure it’s not falsey (as above), you’re only using [1] if the result is not null.

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

Sidebar

Related Questions

I'm using Stroustrup's swan book. I have run into a problem getting output from
I'm having trouble finding/getting any logging output from a web service. I have a
i am using ExecuteOracleNonQuery and getting rowid as output parameter.How can i optimize subsequent
I am trying to retrieving image from sql server 2005 into asp.net web page
I am getting some very annoying behaviour from my perl cgi scripts running under
This is the output I'm getting from the $wpdb->show_errors from Wordpress, and the output
I am getting wierd behaviour with server-api 3.0 when using the @MultipartConfig. When I
I have some code that is used to replace certain page output with other
I am using CrawlSpider to crawl and extract data from a webpage. The start
I'm getting the html from other page with problems in codification. For example: I

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.