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 Perl Discussion :

Problème expression regulière ??


Sujet :

Langage Perl

  1. #1
    Nouveau membre du Club
    Inscrit en
    Août 2005
    Messages
    47
    Détails du profil
    Informations forums :
    Inscription : Août 2005
    Messages : 47
    Points : 28
    Points
    28
    Par défaut Problème expression regulière ??
    Bonjour,

    j'ai crée une expression régulière mais celle-ci est trop large (elle matche mais sur la totalité) et je vois pas trop comment la restreindre pour quelle matche seulement sur chaque ligne :

    Voici mon contenu :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <a href="/q?s=AF2.PA">AF2.PA</a></b></td><td class="yfnc_tabledata1"><small>N/A</small></td><td class="yfnc_tabledata1" align="center"><b>0,00 </b> <nobr><small>1 janv.</small></nobr></td><td class="yfnc_tabledata1" align="center"> <b style="color:#000000;">0,00 (0,00%)</b></td><td class="yfnc_tabledata1" align="right">0</td></tr><tr><td class="yfnc_tabledata1"><b><a href="/q?s=AC.PA">AC.PA</a></b></td><td class="yfnc_tabledata1"><small>ACCOR</small></td><td class="yfnc_tabledata1" align="center"><b>42,79</b> <nobr><small>17h30 </small></nobr></td><td class="yfnc_tabledata1" align="center"><img width="10" height="14" border="0" src="http://us.i1.yimg.com/us.yimg.com/i/us/fi/03rd/up_g.gif" alt="Up"> <b style="color:#008800;">0,03 (0,07%)</b></td><td class="yfnc_tabledata1" align="right">582.661</td></tr><tr><td class="yfnc_tabledata1"><b><a href="/q?s=AGF.PA">AGF.PA</a></b></td><td class="yfnc_tabledata1"><small>AGF</small></td><td class="yfnc_tabledata1" align="center"><b>71,20</b> <nobr><small>17h35 </small></nobr></td><td class="yfnc_tabledata1" align="center"><img width="10" height="14" border="0" src="http://us.i1.yimg.com/us.yimg.com/i/us/fi/03rd/down_r.gif" alt="Down">&nbsp;<b style="color:#cc0000;">0,45 (0,63%)</b></td><td class="yfnc_tabledata1" align="right">271.180</td></tr><tr><td class="yfnc_tabledata1"><b><a href="/q?s=AI.PA">AI.PA</a></b></td><td class="yfnc_tabledata1"><small>AIR LIQUIDE</small></td><td class="yfnc_tabledata1" align="center"><b>143,50</b> <nobr><small>17h33 </small></nobr></td><td class="yfnc_tabledata1" align="center"><img width="10" height="14" border="0" src="http://us.i1.yimg.com/us.yimg.com/i/us/fi/03rd/down_r.gif" alt="Down">&nbsp;<b style="color:#cc0000;">0,70 (0,49%)</b></td><td class="yfnc_tabledata1" align="right">577.960</td></tr><tr><td class="yfnc_tabledata1"><b><a href="/q?s=CGE.PA">CGE.PA</a></b></td><td class="yfnc_tabledata1"><small>ALCATEL</small>
    et voici mon expression :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <a href=\"/q\?s=(.*)\"\>(.*)\<\/a\>\<\/b\>\<\/td\>\<td class=\"yfnc_tabledata1\"\>\<small\>(.*)<\/small\><\/td>
    merci,
    Yann

  2. #2
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 499 184
    Points
    499 184
    Par défaut
    ce serait bien de nous montrer ton fichier avec les retour à la ligne. c'est meilleur pour la visibilité.
    Ensuite, que veux tu recuperer avec ton exprseeion reguliere car on pourra pas t'aider sinon.
    Voilà!!!

  3. #3
    Nouveau membre du Club
    Inscrit en
    Août 2005
    Messages
    47
    Détails du profil
    Informations forums :
    Inscription : Août 2005
    Messages : 47
    Points : 28
    Points
    28
    Par défaut
    Regardes en faite je cherches à une expression regulière qui matche le code et le nom des actions de cette page : http://fr.finance.yahoo.com/q/cp?s=%5ESBF120

    Et tout est dans un tableau pas de \n ?

    Yann

  4. #4
    Expert éminent
    Avatar de Jedai
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2003
    Messages
    6 245
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Avril 2003
    Messages : 6 245
    Points : 8 586
    Points
    8 586
    Par défaut
    Habituellement, pour résoudre ce genre de problème en bourrin, on change les "*" gloutons en "*?" non-gloutons, mais si ça ne marche pas, on est obligé de réfléchir plus profondément à sa regex...

    (NB : tu pourrais utiliser un htmltidy tout de même pour que ce code HTML soit plus lisible !)
    --
    Jedaï

  5. #5
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 499 184
    Points
    499 184
    Par défaut
    ton fichier est illisible, c'est pour cela que je te demander de le soumettre avec des retour à la ligne. Bref, en utilisant Pspad, je l'ai reformaté :
    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
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
     
        <a href="/q?s=AF2.PA">
          AF2.PA</a></b>
        </td>
        <td class="yfnc_tabledata1">
          <small>
            N/A
          </small>
        </td>
        <td class="yfnc_tabledata1" align="center">
          <b>0,00 </b>
          <nobr>
            <small>
              1 janv.
            </small>
          </nobr>
        </td>
        <td class="yfnc_tabledata1" align="center">
          <b style="color:#000000;">
            0,00 (0,00%)</b>
        </td>
        <td class="yfnc_tabledata1" align="right">
          0
        </td>
        </tr>
        <tr>
          <td class="yfnc_tabledata1">
            <b>
              <a href="/q?s=AC.PA">
                AC.PA</a></b>
          </td>
          <td class="yfnc_tabledata1">
            <small>
              ACCOR
            </small>
          </td>
          <td class="yfnc_tabledata1" align="center">
            <b>42,79</b>
            <nobr>
              <small>
                17h30 
              </small>
            </nobr>
          </td>
          <td class="yfnc_tabledata1" align="center">
            <img width="10" height="14" border="0" src="http://us.i1.yimg.com/us.yimg.com/i/us/fi/03rd/up_g.gif" alt="Up">
            <b style="color:#008800;">
              0,03 (0,07%)</b>
          </td>
          <td class="yfnc_tabledata1" align="right">
            582.661
          </td>
        </tr>
        <tr>
          <td class="yfnc_tabledata1">
            <b>
              <a href="/q?s=AGF.PA">
                AGF.PA</a></b>
          </td>
          <td class="yfnc_tabledata1">
            <small>
              AGF
            </small>
          </td>
          <td class="yfnc_tabledata1" align="center">
            <b>71,20</b>
            <nobr>
              <small>
                17h35 
              </small>
            </nobr>
          </td>
          <td class="yfnc_tabledata1" align="center">
            <img width="10" height="14" border="0" src="http://us.i1.yimg.com/us.yimg.com/i/us/fi/03rd/down_r.gif" alt="Down">
            &nbsp;
            <b style="color:#cc0000;">
              0,45 (0,63%)</b>
          </td>
          <td class="yfnc_tabledata1" align="right">
            271.180
          </td>
        </tr>
        <tr>
          <td class="yfnc_tabledata1">
            <b>
              <a href="/q?s=AI.PA">
                AI.PA</a></b>
          </td>
          <td class="yfnc_tabledata1">
            <small>
              AIR LIQUIDE
            </small>
          </td>
          <td class="yfnc_tabledata1" align="center">
            <b>143,50</b>
            <nobr>
              <small>
                17h33 
              </small>
            </nobr>
          </td>
          <td class="yfnc_tabledata1" align="center">
            <img width="10" height="14" border="0" src="http://us.i1.yimg.com/us.yimg.com/i/us/fi/03rd/down_r.gif" alt="Down">
            &nbsp;
            <b style="color:#cc0000;">
              0,70 (0,49%)</b>
          </td>
          <td class="yfnc_tabledata1" align="right">
            577.960
          </td>
        </tr>
        <tr>
          <td class="yfnc_tabledata1">
            <b>
              <a href="/q?s=CGE.PA">
                CGE.PA</a></b>
          </td>
          <td class="yfnc_tabledata1">
            <small>
              ALCATEL
            </small>
    C'est déjà plus lisible non

    Bon je te donne une piste.
    Ton tableau est fait de la sorte :
    une balise TR et 5 TD et ainsi de suite
    Donc tu souhaites recuperer les données de deux premiers TD (colonne code et nom).
    Parcour ton fichier on incremantant une variable à chaque fois que tu parcour un TD. Oublie pas de la mettre à 0 à chaque trouvaille d'une balise fermante TR.
    voilà!!
    sinon y a des modules pour parser du html : HTML:parser ( et CPAN)

  6. #6
    Nouveau membre du Club
    Inscrit en
    Août 2005
    Messages
    47
    Détails du profil
    Informations forums :
    Inscription : Août 2005
    Messages : 47
    Points : 28
    Points
    28
    Par défaut
    En faites j'ai enfin réussi à coder une regex qui matche chaque occurence :
    $_=~ /<tr valign\=\"top\"><td><div align=\"right\"\>([0-9]+) - ([0-9]+) sur ([0-9]+) \| \<b\>/

    Voilà et merci,
    Yann

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 0
    Dernier message: 09/05/2010, 23h22
  2. Problème expression regulière.
    Par Jonathan.Harvey dans le forum Collection et Stream
    Réponses: 4
    Dernier message: 06/08/2009, 03h02
  3. problème expression regulière
    Par Davboc dans le forum SQL
    Réponses: 13
    Dernier message: 17/08/2007, 16h02
  4. [RegEx] problème avec expression regulière
    Par teen6517 dans le forum Langage
    Réponses: 5
    Dernier message: 23/03/2007, 11h39
  5. Variables et Expression Regulière
    Par Temari dans le forum Langage
    Réponses: 5
    Dernier message: 05/08/2005, 01h55

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