Hi All,
I've written a new cgi configuration module that generates the HTML config update forms, verifies the input and saves the data as perl variables.
For the verification I use regexp (obvious). Regexp have never been my strong point, although recently they have been making a lot more sense. I understand $1, $`, $&, $', etc. But I'm not sure if I'm doing some things right. For example I have a regexp that checks for path for illegal characters:-
unless ($input->{$key} =~ /^[a-zA-Z]?:?[^\<\>\:\"\|\?\*]+$/) {
die "Error";
}#unless
If I want to show the user what didn't match to cause the error I'm having to do another regexp:-
unless ($input->{$key} =~ /^[a-zA-Z]?:?[^\<\>\:\"\|\?\*]+$/) {
$input->{$key} =~ /[\<\>\:\"\|\?\*]/;
die "Error, found $&";
}#unless
Am I doing it right? The ^
a-zA-Z?:? is at the beginning as paths my be full windows paths. Although I get the feeling I problem mean ^(
a-zA-Z:)? I'll have to test to be sure. Thinking about it I need yet another regexp so the error doesn't complain about the : in a c:/...
unless ($input->{$key} =~ /^[a-zA-Z]?:?[^\<\>\:\"\|\?\*]+$/) {
$input->{$key} =~ s/^[a-zA-Z]://;
$input->{$key} =~ /[\<\>\:\"\|\?\*]/;
die "Error, found $&";
}#unless
Sure there is an easier way to do it. Hoping one of you rexexp gurus will help.
Lyle
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.