Perl REGEX

Hi,
Can anyone help me to find regular expression for the following in Perl?
"The string can only contain lower case letters (a-z) and no more than one of any letter."
For example: "table" is accepted, whether "dude" is not.
I have coded like this:

$str = "table";
if ($str =~ m/\b([a-z])[^\1]\b/) {
...
}

But it does not work . Any helps would be appreciated. Thanks.

Or are there any other ways besides using regex? Thanks.

You're not going to be able to use a single regular expression to accomplish that. You might try something like:

if ($str !~ /([a-z]).*\1/ && $str =~ /^[a-z]+$/) {
...
}

I agree, a single regexp would be too complicated, but I think you also just did his school/course work for him. :rolleyes:


  1. a-z ↩︎

Gentlemen,

Off my Windows MSDev compiler, I redirect each project to some log files. Because of that, I would like to get the begining word of the mached string line into a variable.

Example contents log file ($log_file):
......
MachineInfo - 0 error(s), 0 warning(s)
....
Libtool - 1 error(s), 0 warning(s)
....
LibSystem - 0 error(s), 0 warning(s)
......

so,
my $error = ' - 0 error(s)';
chomp(my $log_file = "D:\\$proj_$log_dir\\$log_file"));
my @in_log_file = open(IN, "<$log_file");
foreach $_(@in_log_file) {
if ($_ eq $error) {
print "No errors found\n";
} else {
.....
here is where I want the "Libtool" into a variable....
}
}

Thank you in advance for your help.
Chris