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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:28:29+00:00 2026-06-06T03:28:29+00:00

A website I’ve been working on will not match data using a PHP (preg_match)

  • 0

A website I’ve been working on will not match data using a PHP (preg_match) regex pattern that seems to work everywhere else I’ve tested it. That pattern is:

<channel.*?>(.*?)</channel>

It is matched against an RSS feed that has a channel tag.

Now the server I am working on will only produce the correct result if change it to:

<channel.*?>(.*)?</channel>

My regex isn’t the best in the world so I’m wondering if anyone can tell me if there is any significant difference between the two patterns.

Small note: I realize it would probably be better to use SimpleXML etc, but this regex is from a previous application and for various reasons I am not allowed to change it.

Thanks in advance for any insights.

  • 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-06T03:28:31+00:00Added an answer on June 6, 2026 at 3:28 am

    The statement (.*) says “the selection is zero or more characters” and the trailing ? makes it an optional match. By contrast, (.*?) is using a “lazy star” ( *? ) which first attempts to skip the match completely. Check this for more information.

    To understand the difference between a normal (greedy) star and a lazy star, look at the following example in PHP and notice that the greedy star makes the largest match it can with the pattern it is given, while the lazy star “gives up” as soon as it has satisfied the match pattern:

    $inputs = array( 'axb' , 'axxxb' , 'axbxb' , 'axbxxxb' );
    
    // GREEDY STAR (NORMAL)
    foreach( $inputs as $input )
    {
      preg_match( '/a.*b/' , $input , $greedy );
      $greedy_matches[] = $greedy[0];
    }
    
    print "<pre>";
    print_r( $greedy_matches );
    print "</pre>";
    /* 
    Array
    (
        [0] => axb
        [1] => axxxb
        [2] => axbxb
        [3] => axbxxxb
    )
    */
    
    
    
    // LAZY STAR
    foreach( $inputs as $input )
    {
      preg_match( '/a.*?b/' , $input , $lazy );
      $lazy_matches[] = $lazy[0];
    }
    
    print "<pre>";
    print_r( $lazy_matches );
    print "</pre>";
    /* 
    Array
    (
        [0] => axb
        [1] => axxxb
        [2] => axb
        [3] => axb
    )
    */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My website needs a .htaccess file that will redirect a user to index.php when
My website allows visitors to search for homes (using PHP and MySql). After the
My website at http://derek.genevievehoward.com/ will not display in Firefox, even though the HTML and
My website has tons of large images that reduces my site speed. I want
Most website I can parse its title easily with RegEx (. ) or \s
My website structure is a header, content, footer. My goal is that every time
My website project includes taking data from the user in the form of two
My website (running on the express framework) suddenly started complaining that it needed a
My website has been broken since Dreamhost upgraded their servers a couple of weeks
My website has a search procedure that runs very slowly. One thing that slows

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.