cosmicperl has asked for the wisdom of the Perl Monks concerning the following question:
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]?:?[^\<\>\:\"\|\?\*]+$/) { die "Error"; }#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} =~ /[\<\>\:\"\|\?\*]/; die "Error, found $&"; }#unless
Sure there is an easier way to do it. Hoping one of you rexexp gurus will help.unless ($input->{$key} =~ /^[a-zA-Z]?:?[^\<\>\:\"\|\?\*]+$/) { $input->{$key} =~ s/^[a-zA-Z]://; $input->{$key} =~ /[\<\>\:\"\|\?\*]/; die "Error, found $&"; }#unless
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Showing why a Regexp didn't match
by pc88mxer (Vicar) on Apr 12, 2008 at 00:52 UTC | |
by hipowls (Curate) on Apr 12, 2008 at 02:05 UTC | |
Re: Showing why a Regexp didn't match
by rhesa (Vicar) on Apr 12, 2008 at 01:32 UTC |