in reply to Difficult? regex

The regex /\?(C=N;O=D|C=M;O=A)?$/ has a question mark after (C=N;O=D|C=M;O=A) and therefore it is optional. The regex matches any URL that terminates with a '?'.

Replies are listed 'Best First'.
Re^2: Difficult? regex
by Anonymous Monk on Feb 22, 2008 at 11:46 UTC
    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)$/;

      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.