[RESOLU] soustraction d'une chaîne (REGEX)

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : [RESOLU] soustraction d'une chaîne (REGEX)

Re: soustraction d'une chaîne (REGEX)

par SamOliver » 24 févr. 2015, 17:40

Merci bien pour votre aide, j'en suis tres reconnaissant :)

Re: soustraction d'une chaîne (REGEX)

par @rthur » 24 févr. 2015, 16:21

Voici une regex qui devrait fonctionner sur la base de ce que tu as fait :
(<text:p text:style-name="[A-Z0-9]+">AB4</text:p>)
Tu peux la voir en action sur ton exemple ici :
https://regex101.com/r/jI1qE3/1

Re: soustraction d'une chaîne (REGEX)

par SamOliver » 24 févr. 2015, 15:48

en fait ele resultat que je recoit est le suivant

Code : Tout sélectionner

<text:p text:style-name="P32">AB1</text:p> </table:table-cell> <table:table-cell table:style-name="Tableau3.A2" office:value-type="string"> <text:p text:style-name="P21">AB2</text:p> </table:table-cell> <table:table-cell table:style-name="Tableau3.A2" office:value-type="string"> <text:p text:style-name="P21">AB3</text:p> </table:table-cell> <table:table-cell table:style-name="Tableau3.A2" office:value-type="string"> <text:p text:style-name="P21">AB4</text:p> </table:table-cell> <table:table-cell table:style-name="Tableau3.A2" office:value-type="string"> <text:p text:style-name="P21">AB5</text:p> </table:table-cell> <table:table-cell table:style-name="Tableau3.F2" office:value-type="string"> <text:p text:style-name="P21">AB6</text:p>
Moi je veux juste la chaine

Code : Tout sélectionner

<text:p text:style-name="P21">AB4</text:p>

Re: soustraction d'une chaîne (REGEX)

par SamOliver » 24 févr. 2015, 15:40

Justement je fais comment pour avoir que la chaine que je recherche (pas toute la chaine) ?

Re: soustraction d'une chaîne (REGEX)

par tof73 » 24 févr. 2015, 15:32

$matches[0] comprend la chaine entière, $matches[1], ce qu'il y a entre ()

soustraction d'une chaîne (REGEX)

par SamOliver » 24 févr. 2015, 15:28

Bonjour

J'ai la chaîne suivante

Code : Tout sélectionner

<table:table-row table:style-name="Tableau3.2"> <table:table-cell table:style-name="Tableau3.A2" office:value-type="string"> <text:p text:style-name="P32">AB1</text:p> </table:table-cell> <table:table-cell table:style-name="Tableau3.A2" office:value-type="string"> <text:p text:style-name="P21">AB2</text:p> </table:table-cell> <table:table-cell table:style-name="Tableau3.A2" office:value-type="string"> <text:p text:style-name="P21">AB3</text:p> </table:table-cell> <table:table-cell table:style-name="Tableau3.A2" office:value-type="string"> <text:p text:style-name="P21">AB4</text:p> </table:table-cell> <table:table-cell table:style-name="Tableau3.A2" office:value-type="string"> <text:p text:style-name="P21">AB5</text:p> </table:table-cell> <table:table-cell table:style-name="Tableau3.F2" office:value-type="string"> <text:p text:style-name="P21">AB6</text:p> </table:table-cell> </table:table-row>


J'aimerai soustraire la chaîne suivante :

Code : Tout sélectionner

<text:p text:style-name="P21">AB4</text:p>
sachant que P21 est une variable inconnue

Quand je fais

Code : Tout sélectionner

$reg1 = "#<text:p text:style-name=(.*)>AB4</text:p>#"; preg_match_all($reg1, $this->xml, $matches);
ça me retourne la chaîne entière, alors que je veux soustraire que la chaîne en question.

Code : Tout sélectionner

<text:p text:style-name="P21">AB4</text:p>

Merci d'avance pour votre aide.