IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Liste exhaustive de ce qui "match"


Sujet :

Langage PHP

  1. #21
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    @badaze
    Ton 1er appel était faux, car il manquait les espaces " " de la regex pattern *.
    Dans le 2eme, tu compliques inutilement, car les espaces sont aussi des caractères.

    Donc, on peut simplement grouper ' chap' et ' p' :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    foreach(cartesien(array(
         cartesien(array(array('chap'),array('i','a'))),
         cartesien(array(array(' chap'),array('o','a'))),
         cartesien(array(array(' p'),array('a','i'))),
         cartesien(array(array('t'),array('a','i'))),
         cartesien(array(array('p'),array('o','a')))
         )) as $sousTableau)
    {
    Cela dit, ça a l'air très fonctionnel !

    * une regex serait plutôt de la forme : 'chap[ia] chap[oa] p[ai]t[ai]p[oa]';
    Dernière modification par Invité ; 07/08/2018 à 08h16.

  2. #22
    Membre émérite
    Avatar de badaze
    Homme Profil pro
    Chef de projets info
    Inscrit en
    Septembre 2002
    Messages
    1 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Chef de projets info
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2002
    Messages : 1 412
    Points : 2 522
    Points
    2 522
    Par défaut
    Dans mon premier message je voulais seulement montrer la faisabilité. Par contre je ne comprends pas pourquoi je n’ai pas pensé à ta méthode. Les causes que je vois sont l’heure tardive, la chaleur d’une nuit italienne, le prosecco, le vin rouge et le limoncello.
    Cela ne sert à rien d'optimiser quelque chose qui ne fonctionne pas.

    Mon site : www.emmella.fr

    Je recherche le manuel de l'Olivetti Logos 80B.

  3. #23
    Expert éminent Avatar de CosmoKnacki
    Homme Profil pro
    Justicier interdimensionnel
    Inscrit en
    Mars 2009
    Messages
    2 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Justicier interdimensionnel

    Informations forums :
    Inscription : Mars 2009
    Messages : 2 858
    Points : 6 556
    Points
    6 556
    Par défaut
    ERRATUM: j'ai commis une petite erreur dans la tokenization. L'expression correcte est:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    // tokenization
    $tokens = (function ($regex) {
        if ( preg_match_all('~ [^()|]+ | (?<![^(|)]) (?![^(|)]) | [()|] ~x', $regex, $matches) )
            yield from $matches[0];
    })($pattern);
    Brachygobius xanthozonus
    Ctenobrycon Gymnocorymbus

  4. #24
    Membre émérite
    Avatar de badaze
    Homme Profil pro
    Chef de projets info
    Inscrit en
    Septembre 2002
    Messages
    1 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Chef de projets info
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2002
    Messages : 1 412
    Points : 2 522
    Points
    2 522
    Par défaut
    Version orientée objet.

    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
     
    <?php
    class matchAll {
     private $arrayResult = array();
     
     public function __construct($texte) {
      $po      = '\(';
      $pf      = '\)';
      $pattern = "/(([^$po]*)($po([^$pf]*)$pf)*)/";
      preg_match_all($pattern,$texte,$out);
     
      foreach($out[2] as $key => $constant) {
       $this->add($constant,$out[4][$key]);
      }
     }
     
     private function cartesien($arrayOfArrays) {
        $result = array();
        $arrLen = count($arrayOfArrays);
        for ($i=0;$i < $arrLen;$i++) {
         foreach ($arrayOfArrays[$i] as $currentValue) {
          if (isset($result[$i-1])) {
           foreach($result[$i-1] as $previousArray) {
            $result[$i][] = array_merge($previousArray, array($currentValue));
           }
          }
          else {
           $result[$i][] = array($currentValue);
          }    
         }
        }    
        return $result[$arrLen-1];
     }
     
     private function add($constant,$variable) {
      $arrayResult       = $this->cartesien(array($this->arrayResult,array($constant),explode('|',$variable)));
      $this->arrayResult = array();
      foreach($arrayResult as $value) {
       $this->arrayResult[] = implode('',$value);
      }
     }
     
     public function getResult() {
      return $this->arrayResult;
     }
    }
    $a = new matchAll('chap(i|a) chap(o|a) p(a|i)t(a|i)p(o|a) toto');
    foreach($a->getResult() as $value)
    {
     print "$value<br/>";
    }

    Donne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    chapi chapo patapo toto
    chapa chapo patapo toto
    chapi chapa patapo toto
    chapa chapa patapo toto
    chapi chapo pitapo toto
    chapa chapo pitapo toto
    chapi chapa pitapo toto
    chapa chapa pitapo toto
    chapi chapo patipo toto
    chapa chapo patipo toto
    chapi chapa patipo toto
    chapa chapa patipo toto
    chapi chapo pitipo toto
    chapa chapo pitipo toto
    chapi chapa pitipo toto
    chapa chapa pitipo toto
    chapi chapo patapa toto
    chapa chapo patapa toto
    chapi chapa patapa toto
    chapa chapa patapa toto
    chapi chapo pitapa toto
    chapa chapo pitapa toto
    chapi chapa pitapa toto
    chapa chapa pitapa toto
    chapi chapo patipa toto
    chapa chapo patipa toto
    chapi chapa patipa toto
    chapa chapa patipa toto
    chapi chapo pitipa toto
    chapa chapo pitipa toto
    chapi chapa pitipa toto
    chapa chapa pitipa toto
    Cela ne sert à rien d'optimiser quelque chose qui ne fonctionne pas.

    Mon site : www.emmella.fr

    Je recherche le manuel de l'Olivetti Logos 80B.

Discussions similaires

  1. supprimer une table qui a des quotes dans son nom
    Par kleenex dans le forum Access
    Réponses: 2
    Dernier message: 17/10/2005, 16h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo