Is there a way to do a greater than and less than in a regular expression? I am looking to list only images that are less than 10 in there name.

pan1.jpg
pan2.jpg
pan3.jpg
pan4.jpg ... up to pan10.jpg

I was able to get it to just list pan1.jpg to pan9.jpg using the following expression, (pan[[1-9]$]).jpg

I need it to include the 10 as well. I like to know if less than and greater than are available.

    I'd use backreferences: extract the number between "pan" and ".jpg", then compare it with whatever value you want it to be less than or equal to.

    Like this:

    preg_match("/pan(\d+).jpg/", $subject, $matches);
    
    if ($matches[1] < 10)
    {
        echo $matches[0] . "\n";
    }
    

      Hey, thanks very much for your method and help.. I also did manage to figure out what to use. (pan([1-9]|1[0])).jpg

        Write a Reply...