Re: Extraction nombre décimaux.

Liste des GroupesRevenir à fcl regexp 
Sujet : Re: Extraction nombre décimaux.
De : schaefer (at) *nospam* alphanet.ch (Marc SCHAEFER)
Groupes : fr.comp.lang.regexp
Date : 23. Oct 2022, 15:25:44
Autres entêtes
Organisation : Posted through news.alphanet.ch
Message-ID : <tj3fco$b2h$1@shakotay.alphanet.ch>
References : 1
User-Agent : tin/2.4.3-20181224 ("Glen Mhor") (UNIX) (Linux/4.19.0-22-amd64 (x86_64))
kurtz le pirate <kurtzlepirate@free.fr> wrote:
  @floatnum = $line =~ /[-+]?([0-9]*\.[0-9]+|[0-9]+)/g;

comme [-+]? n'est pas entre (), Perl ne va pas l'extraire et il ne va
pas finir dans le tableau.

@floatnum = $line =~ /([-+]?[0-9]*\.[0-9]+|[0-9]+)/g;

démo:

schaefer@reliand:/tmp$ ./a.pl
1.2
1.2
1.2 4.5
1.2, 4.5
-1.2
-1.2
-1.2 4.5
-1.2, 4.5

schaefer@reliand:/tmp$ cat a.pl
#! /usr/bin/perl

use strict;
use warnings;

while (my $line = <STDIN>) {
   my @f = $line =~ /([-+]?[0-9]*\.[0-9]+|[0-9]+)/g;

   print join(', ', @f), "\n";
}

Date Sujet#  Auteur
23 Oct 22 * Extraction nombre décimaux.12kurtz le pirate
23 Oct 22 +* Re: Extraction nombre décimaux.6Olivier Miakinen
23 Oct 22 i`* Re: Extraction nombre décimaux.5Marc SCHAEFER
23 Oct 22 i +* Re: Extraction nombre décimaux.2Richard Hachel
23 Oct 22 i i`- Re: Extraction nombre décimaux.1Olivier Miakinen
23 Oct 22 i `* Re: Extraction nombre décimaux.2Olivier Miakinen
24 Oct 22 i  `- Re: Extraction nombre décimaux.1Marc SCHAEFER
23 Oct 22 +- Re: Extraction nombre décimaux.1Marc SCHAEFER
24 Oct 22 `* Re: Extraction nombre décimaux.4kurtz le pirate
24 Oct 22  `* Re: Extraction nombre décimaux.3Olivier Miakinen
25 Oct 22   `* Re: Extraction nombre décimaux.2kurtz le pirate
26 Oct 22    `- Re: Extraction nombre décimaux.1Olivier Miakinen

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal