2009/11/16 Daniel Burgaud <burg...@gmail.com> > Hi, > > my $line = "Unconfirmed"; > > I need an RE that will give me a TRUE value if the string is 2~8 chars > long. > otherwise, it gives FALSE; > > I tried > > if ($line =~ /\S{2,8}/) { > return 1; > } else { > return 0; > } > > However this does not work. > > I cannot use length($line) because it has to be Regular expression. > > Thanks. > > Dan > > You probably want the start and end of line anchors:
use strict; use warnings; while (<DATA>) { print _regexp( $_ ) ? "TRUE\n" : "FALSE\n"; } sub _regexp { my $line = shift; if ( $line =~ /^\S{2,8}$/) { return 1; } else { return 0; } } __DATA__ I saw an elephant eating a rhinoceros Just in
_______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs