A one liner would be
$is_bad = $string =~ /[^cCdeEfGhiIkKlLmMrRstTvVxX]/ || $string =~ /(.).*\1/;
naturally...if you need only one regex then you could say
$is_bad = $string =~ /[^cCdeEfGhiIkKlLmMrRstTvVxX]|((.).*\2)/;

I'm not sure if the character class is right for your app (I don't know the
exact letters...just copied from below...but you can change that.

Good Luck!
Tanton

-----Original Message-----
From: Michel Blanc
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: 8/23/2001 9:11 AM
Subject: Re: Regex help

Jeff 'japhy/Marillion' Pinyan a écrit :

> Someone else has already shown the general approach for ensuring a
> unique-character string:
> 
>   sub unique_characters {
>     $_[0] =~ /(.).*?\1/s ? 0 : 1
>   }
> 
> We can extrapolate upon this idea and test afterward that the string
> doesn't contain any unwanted characters:
> 
>   sub unique_char_set {
>     my ($str, $chars) = @_;
>     return 0 if $str =~ /[^\Q$chars\E]/;
>     return !($str =~ /(.).*?\1/s);
>   }

Thanks for your response guys. This is very useful.

In fact, since I needed a one liner (I forgot to say that) for a
regex-based dispatch table, I tried to convert that to :


($str !~ /(c|C|d|e|E|f|G|h|i|I|k|K|l|L|m|M|r|R|s|t|T|v|V|x|X).*?\1/s);

But this doesn't fail if unwanted characters are in.

So I am afraid that we'll arrive at (??{ ... }) 
What I am trying to do is some kind of shell. Command dispatching is
done via a hash containing "regex" => coderef style data. That's why I
am looking for a one--liner.

Thanks ! 
Michel.
-- 
Michel Blanc
Centre Multimédia Erasme/Parc d'activités innovantes
69930 Saint Clément-les-places
Tel : +33-(0)4-74-70-68-40 / Fax : +33-(0)4-74-70-68-40

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to