Regex geedy and non-greedy match

user-pic
Vote 0 Votes

.* is greedy match
.*? is non-greedy match

PHP example:
$str="abc123abc456abc";
preg_match("/abc(.*)abc/",$str,$match);
echo $match[1]; // result is 123abc456
preg_match("/abc(.*?)abc/",$str,$match);
echo $match[1]; // result is 123

About this Entry

This page contains a single entry by Pank published on May 12, 2016 10:19 AM.

sshpass was the previous entry in this blog.

OTA Images for Nexus Devices is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Monthly Archives