in reply to Re: Difficult? regex
in thread Difficult? regex

It has a question mark because I just copied and pasted the prior regex that matches image files below:
# ignore any common image files return if $uri->path =~ /\.(gif|jpg|jpeg|png)?$/;
Does this mean that the regex for filtering image files will also match anything that ends in a period? I thought the final question mark would make a "non greedy" match. I should note that I'm not much of a Perl programmer and definitely not very good at regex expressions. I've read several sites on regex and tried all sort of variations on this regex but just can't get it to work. I've put several hours of work into this already so I'm not just looking for someone to write the code for me. Until now that is :-) So anyway, I also tried the regex without the question mark and it doesn't work either:
return if $uri->path =~ /\?(C=N;O=D|C=M;O=A)$/;

Replies are listed 'Best First'.
Re^3: Difficult? regex
by hipowls (Curate) on Feb 23, 2008 at 00:52 UTC

    The question mark makes the term optional. It doesn't make sense here to use non-greedy matches, there isn't a '*' or '+' modifier to say "grab as much as you can". In this case you want to match the file endings.