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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:05:15+00:00 2026-06-14T20:05:15+00:00

i got a problem occuring when using regular expressions: php> $html = <html><head><body><h1>hello world</h1><img

  • 0

i got a problem occuring when using regular expressions:

php> $html = "<html><head><body><h1>hello world</h1><img src=\"data:rawIMGdata\" /><p/><img src=\"sdfsdf.jpg\" title=\"pic1\" /><p/><div class=\"myclass\"><img src=\"data:imageData\" /></div><img alt=\"bla\" src=\"bla.jpg\" title=\"bla\" /></body></html>";
php> $pat = '/<img.*src="(data:.*)"/m';
php> preg_match_all($pat, $html, $matching);
php> var_dump($matching);
array(2) {
  [0]=>
  array(1) {
    [0]=>
    string(169) "<img src="data:rawIMGdata" /><p/><img src="sdfsdf.jpg" title="pic1" /><p/><div class="myclass"><img src="data:imageData" /></div><img alt="bla" src="bla.jpg" title="bla""
  }
  [1]=>
  array(1) {
    [0]=>
    string(63) "data:imageData" /></div><img alt="bla" src="bla.jpg" title="bla"
  }  
}

My expected output would be just an occurence of “data:imageData” in the second array and moreover there should be two matches (“data:rawIMGdata”)

Did i define my regex a wrong way?

Regards,
Broncko

  • 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-14T20:05:17+00:00Added an answer on June 14, 2026 at 8:05 pm

    You might want to consider using DOM Document for parsing HTML, although if this example is a complex as it is going to get then you can probably get away with regex; DOM Document will always be more robust though.

    Try this:

    /<img.*?src="(data:[^"]*)"/m
    

    The ? sets the * to be non-greedy (so it will get the minimum match, by default it grabs as much as it can)

    And rather than match anything, you can match anything that isn’t a ” with [^”].

    The .* before was being greedy and matching up to the ” in another element

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

Sidebar

Related Questions

I got problem with sending data in Android using httpPost. I found some example,
Got a problem with Apache and PHP-files of Wordpress. When I go to any
got a problem, can't get my head around this jquery and would appreciate your
I got problem with core data, I had a table that exactly look like
I got problem to request a PartialView using ajax In my point of view
everyone I got problem here I need to update a plist data in a
Got problem with opening custom context menu using advanced user interactions API in Selenium
I got problem with parsing data. I send ajax request and as I can
I got problem with using split command. The input string is as follows: 080821_HWI-EAS301_0002_30ALBAAXX:1:8:1649:2027
I have a problem trying to get my head around using UTF8 with Poco::XML::XMLWriter

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.