Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Difficult? regex

by hipowls (Curate)
on Feb 22, 2008 at 11:03 UTC ( [id://669517]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://669517]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-24 00:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found