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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:43:34+00:00 2026-05-23T19:43:34+00:00

I am being struggling with this regex expression long time but i cannot find

  • 0

I am being struggling with this regex expression long time but i cannot find any fix. I used the javascript based tools to test and write the expression. When putting into the php page and matching with preg the results are different.

/(<img\b src=)"([^"]+)"(.* class=".*colorme(?:.|[^"]*)"[^>]+>)/

And the examples to test are here, the first should not be matched. THIS ALL WORKS with javascript, but not with php, only the classes class=”colorme” will be matched. Am I missing something ?

<img src="http://test.jpg" class="then" border="0" width="123" height="83">

<img src="test.jpg" border="0" alt="well watch picture" alt="tersts" class="really colorme" width="228" height="138">

<img src="test.jpeg" class="colorme then" border="0" width="123" height="83">

<img src="test" border="0" width="123" height="83" class="pic colorme then" with="me">

<img src="tests" border="0" class="colorme" width="123" height="83">
  • 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-23T19:43:34+00:00Added an answer on May 23, 2026 at 7:43 pm

    With DOM & no fancy expressions…

    <?php 
    $doc =<<<DEMO
    <img src="http://test.jpg" class="then" border="0" width="123" height="83">
    <img src="test.jpg" border="0" alt="well watch picture" alt="tersts" class="really colorme" width="228" height="138">
    <img src="test.jpeg" class="colorme then" border="0" width="123" height="83">
    <img src="test" border="0" width="123" height="83" class="pic colorme then" with="me">
    <img src="tests" border="0" class="colorme" width="123" height="83">
    DEMO;
    
    $xml = new DOMDocument();
    //Or you could use for locally saved files
    //@$xml->loadHTMLFile('savedfile.html');
    @$xml->loadHTML($doc);
    foreach($xml->getElementsByTagName('img') as $image) {
        if(strstr($image->getAttribute('class'),'colorme')==true){
            $images[] = $image->getAttribute('src');
        }
    }
    print_r($images);
    ?>
    

    Outputs:

    Array (
        [0] => test.jpg
        [1] => test.jpeg
        [2] => test
        [3] => tests )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been struggling on this thing for a week without being able to find
I remember struggling with this before but I've googled and can't find the reference.
Just struggling with a Javascript class being used as a method for some cometishian
Being new to test based development, this question has been bugging me. How much
This is probably a super simple question, but I'm struggling to come up with
I'm struggling to find a good solution to this problem. In a view controller's
Sounds simple, but struggling to get this working. I thought it would be easy
I have done this many times in PHP using JS but being new to
Man being developer is great but days like this make you want to become
This is probably a very trivial question but I've been struggling with it for

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.