Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > fr.comp.lang.regexp > #249 > unrolled thread

Trouver le premier = (Il y avait longtemps !)

Started byOtomatic <otomatic@oto.invalid>
First post2025-10-02 15:38 +0200
Last post2025-10-03 09:18 +0200
Articles 3 — 2 participants

Back to article view | Back to fr.comp.lang.regexp


Contents

  Trouver le premier = (Il y avait longtemps !) Otomatic <otomatic@oto.invalid> - 2025-10-02 15:38 +0200
    Re: Trouver le premier = (Il y avait longtemps !) Olivier Miakinen <om+news@miakinen.net> - 2025-10-02 15:48 +0200
      Re: Trouver le premier = (Il y avait longtemps !) Otomatic <otomatic@oto.invalid> - 2025-10-03 09:18 +0200

#249 — Trouver le premier = (Il y avait longtemps !)

FromOtomatic <otomatic@oto.invalid>
Date2025-10-02 15:38 +0200
SubjectTrouver le premier = (Il y avait longtemps !)
Message-ID<h4vsdk1blivm4qanrojpdkcqraqgntnon3@4ax.com>
Bonjour,

Soit le résultat des Define Apache :
> Define: APACHE24=Apache2.4
> Define: VERSION_APACHE=2.4.65
> Define: INSTALL_DIR=E:/wamp64
> Define: APACHE_DIR=E:/wamp64/bin/apache/apache2.4.65
> Define: SRVROOT=E:/wamp64/bin/apache/apache2.4.65
> Define: PHPROOT=E:/wamp64/bin/php/php
> Define: MYSQLDUMPERLOCAL=local
> Define: FCGIPHPVERSION=8.3.26
> Define: CERTIFS=E:/wamp64/bin/Certs
> Define: CERTIFICATS=E:/wamp64/bin/certificats
> Define: FCGIPHPOPTIONS= -d upload_max_filesize=256M -d post_max_size=256M -d max_execution_time=360 -d max_input_time=360

Par une regexp je cherche à obtenir le nom et le contenu de la variable
Apache. La regexp est :
preg_match_all("~^Define: (.+)=(.+)~m",$output, $matches)

Cela fonctionne très bien, sauf pour le dernier Define !

Le resultat est :
[02-Oct-2025 15:05:41 Europe/Paris] matches1=Array
(
    [0] => APACHE24
    [1] => VERSION_APACHE
    [2] => INSTALL_DIR
    [3] => APACHE_DIR
    [4] => SRVROOT
    [5] => PHPROOT
    [6] => MYSQLDUMPERLOCAL
    [7] => FCGIPHPVERSION
    [8] => CERTIFS
    [9] => CERTIFICATS
    [10] => FCGIPHPOPTIONS= -d upload_max_filesize=256M -d
post_max_size=256M -d max_execution_time=360 -d max_input_time
)

matches2=Array
(
    [0] => Apache2.4
    [1] => 2.4.65
    [2] => E:/wamp64
    [3] => E:/wamp64/bin/apache/apache2.4.65
    [4] => E:/wamp64/bin/apache/apache2.4.65
    [5] => E:/wamp64/bin/php/php
    [6] => local
    [7] => 8.3.26
    [8] => E:/wamp64/bin/Certs
    [9] => E:/wamp64/bin/certificats
    [10] => 360
)

Comment faire pour que ce soit le premier signe = et non pas le dernier
qui soit pris en compte ?

Merci.

[toc] | [next] | [standalone]


#250

FromOlivier Miakinen <om+news@miakinen.net>
Date2025-10-02 15:48 +0200
Message-ID<10blvsb$300c$1@cabale.usenet-fr.net>
In reply to#249
Le 02/10/2025 à 15:38, Otomatic a écrit :
> 
> preg_match_all("~^Define: (.+)=(.+)~m",$output, $matches)
> 
> [...]
> 
> Comment faire pour que ce soit le premier signe = et non pas le dernier
> qui soit pris en compte ?

[non testé]
Remplacer le premier .+ par .+? :
preg_match_all("~^Define: (.+?)=(.+)~m",$output, $matches)

Mot-clé : greedy

[toc] | [prev] | [next] | [standalone]


#251

FromOtomatic <otomatic@oto.invalid>
Date2025-10-03 09:18 +0200
Message-ID<03uudktndfjp9k609iif181r07moskupkp@4ax.com>
In reply to#250
Olivier Miakinen <om+news@miakinen.net> écrivait :

> Le 02/10/2025 à 15:38, Otomatic a écrit :
> > 
> > preg_match_all("~^Define: (.+)=(.+)~m",$output, $matches)
> > 
> > [...]
> > 
> > Comment faire pour que ce soit le premier signe = et non pas le dernier
> > qui soit pris en compte ?
> 
> [non testé]
> Remplacer le premier .+ par .+? :
> preg_match_all("~^Define: (.+?)=(.+)~m",$output, $matches)
> 
> Mot-clé : greedy

C'est OK ! J'ai regardé les docs avec le mot clé "greedy" et je pense
avoir compris.

Merci.

[toc] | [prev] | [standalone]


Back to top | Article view | fr.comp.lang.regexp


csiph-web