Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 27/07/2007, à 18:27

i M@N

[resolu] problème de regex

Hello.

Je voudrais adapter un script perl pour irssi qui répondrait automatiquement au mot "bonsoir" ou "bonjour" sur un chan.
Mais je voudrais pas qu'il réponde si on dit "rebonsoir" par exemple : en clair je cherche la regex qui ne prendrait en compte le mot "bonsoir" seulement si il est précédé d'un espace ou si il débute une ligne.
Voilà le bout de code :

sub event_privmsg {
my ($server, $data, $nick) =@_;
my ($target, $text) = $data =~ /^(\S*)\s:(.*)/;
	if ($target =~ /^# */i) {
		if ( $text =~ /.*bonsoir.*|.*bonjour.*|.*hello.*/i) {
	        $server->command ( "msg $target hello $nick : )" );
	        }
	}
	else {
		if ( $text =~ /.*bonsoir.*|.*bonjour.*|.*hello.*/i) {
                $server->command ( "msg $nick hello $nick : )" );
                }
	}
}

J'ai eu beau chercher j'ai pas trouvé ... je pense que c'est au niveau de cette ligne :

my ($target, $text) = $data =~ /^(\S*)\s:(.*)/;

Merci d'avance,

@+...

Dernière modification par i M@N (Le 27/07/2007, à 23:52)


1 x Intel(R) Core i7 2600K CPU 3.4GHz Debian sid = roxX !
1 x MSi Wind U100 Debian sid = roxX !!
Read The F***in' Manual or die tryin' !
webmaster @ http://www.rastavibes.net reggae shop

Hors ligne

#2 Le 27/07/2007, à 23:22

i M@N

Re : [resolu] problème de regex

Reuh ...

Bon /me gros boulet, c'était pas la bonne regex que je bidouillais ... il fallait modifier :

if ( $text =~ /.*bonsoir.*|.*bonjour.*|.*hello.*/i) {

en

if ( $text =~ /bonsoir|bonjour|hello/i) {

Tout simplement.

Surcouf a écrit :

les .* en regex, c'est n'importe quel caractère, plusieurs fois

Merci Surcouf sur #ubuntu-fr smile

@+...


1 x Intel(R) Core i7 2600K CPU 3.4GHz Debian sid = roxX !
1 x MSi Wind U100 Debian sid = roxX !!
Read The F***in' Manual or die tryin' !
webmaster @ http://www.rastavibes.net reggae shop

Hors ligne