[Perl] problème de regex

Répondre
i M@N
i M@N
Déconnecté
One Love, One Heart, One Unity.
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 :
  1. sub event_privmsg {
  2. my ($server, $data, $nick) =@_;
  3. my ($target, $text) = $data =~ /^(\S*)\s:(.*)/;
  4. if ($target =~ /^# */i) {
  5. if ( $text =~ /.*bonsoir.*|.*bonjour.*|.*hello.*/i) {
  6. $server->command ( "msg $target hello $nick : )" );
  7. }
  8. }
  9. else {
  10. if ( $text =~ /.*bonsoir.*|.*bonjour.*|.*hello.*/i) {
  11. $server->command ( "msg $nick hello $nick : )" );
  12. }
  13. }
  14. } 

J'ai eu beau chercher j'ai pas trouvé ... je pense que c'est au niveau de cette ligne :
  1. my ($target, $text) = $data =~ /^(\S*)\s:(.*)/; 

Merci d'avance,

@+...
i M@N
i M@N
Déconnecté
One Love, One Heart, One Unity.
Reuh ...

Bon /me gros boulet, c'était pas la bonne regex que je bidouillais ... il fallait modifier :
  1. if ( $text =~ /.*bonsoir.*|.*bonjour.*|.*hello.*/i) { 

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

Tout simplement.
[quote=Surcouf]les .* en regex, c'est n'importe quel caractère, plusieurs fois[/quote]
Merci Surcouf sur #ubuntu-fr :)

@+...
moogli
moogli
Déconnecté
Il en faut peu pour être heureux !!!!!
plop

le site qui va bien http://www.expreg.com :-)

@+
mojorisin
mojorisin
Déconnecté
echo ’16i[q]sa[ln0=aln100%Pln100/snlbx]sbA0D4D465452snlbxq’|dc
Voila une solution :
if ( $text =~ /\b(?:bon(?:soir|jour)|hello)\b/i)
i M@N
i M@N
Déconnecté
One Love, One Heart, One Unity.
Hello.

Merci les mecs. smiley

En fait faut surtout que je me penche sur perl pour lui apprendre à compter à ce script : on dit hello il dit hello, on te répond si tu dit hello il redit hello ... c'est sans fin. smiley

@+...
Répondre
Accès rapide :

Remonter Remonter
L'éditeur javascript - CSS - Gentoo - Tutoriaux PHP - Tutoriels PHP - Php - Breizh Blog