Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hello everyone,
I have the following regular expression:
/[A-Z0-9]+[A-Z0-9-]+[A-Z0-9]{1}/i
but it doesn't appear to work. (It is supposed to match one part of a domain name)
I've tried testing with:
but then it doesn't seem to match properly:#!/usr/bin/perl -w # my $domain = $ARGV[0]; print "Got $domain\n"; if ($domain =~ /[A-Z0-9]+[A-Z0-9-]+[A-Z0-9]{1}/i) { print "$domain matched\n\n"; } else { print "$domain did not match\n\n"; }
[~/code/perl] ./match.pl someRandomName. Got someRandomName. someRandomName. matched [~/code/perl] ./match.pl someRandomName- Got someRandomName- someRandomName- matched
Can someone tell me why it is matching the . or the - at the end of the line?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regular expression matching when it shouldn't
by OeufMayo (Curate) on Aug 15, 2001 at 13:30 UTC | |
|
Re: Regular expression matching when it shouldn't
by tachyon (Chancellor) on Aug 15, 2001 at 13:50 UTC | |
|
Re: Regular expression matching when it shouldn't
by Hofmator (Curate) on Aug 15, 2001 at 14:30 UTC | |
|
Re: Regular expression matching when it shouldn't
by dga (Hermit) on Aug 15, 2001 at 22:41 UTC | |
|
Re: Regular expression matching when it shouldn't
by FoxtrotUniform (Prior) on Aug 15, 2001 at 21:05 UTC |