Kevin Zembower wrote: > > Thank you all for some first thoughts and clarifying questions. > > I'm trying to discard any URL with any character that is not an upper- or lower-case > letter, digit, or the characters $-_.+!*'(), . I realize that some other characters > can be > used in special circumstances, but I don't have to allow for any of these in my > program. > > I thought that my perl statement: > if ($url =~ /^[^A-Za-z0-9$-_.+!*'(),]+$/) { #if there are any invalid URL > characters in the string > # Remember, special regex > characters lose their meaning inside [] > print "Invalid character in URL at line $.: $url\n"; > next; > } > is saying: > if the variable $url contains any characters not in the set > [A-Za-z0-9$-_.+!*'(),]+$/), print "Invalid ..." > > So, I think I need help in two areas; Do I have my logic backwards because I'm > trying to match any > character in a variable, and, How do I write the match statement to do what I want.
Hi Kevin. Take note of Charles' points, but also note that Perl is trying to expand the built-in variable $- into your regex. This is almost certainly zero unless you're using formats, so you're including the digit zero for a second time instead of dollar and dash. If you escape the dollar and code [A-Za-z0-9\$-_.+!*'(),] instead, then your class will include all characters from dollar up to underscore. So you need to escape both dollar and dash: if ($url =~ /[A-Za-z0-9\$\-_.+!*'(),]/) { # Remember MOST special regex characters lose their meaning inside [] print "Invalid character in URL at line $.: $url\n"; next; } HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>