Article View: es.comp.os.linux.programacion
Article #514Re: Ayuda con expresiones regulares
From: Gonzalo Pérez de Olaguer Córdoba
Date: Thu, 12 Apr 2007 22:48
Date: Thu, 12 Apr 2007 22:48
49 lines
2646 bytes
2646 bytes
Hola José Luis Pérez Diez <jluis@agujero-negro.escomposlinux.org>
el Wed, 11 Apr 2007 17:52:23 +0200 escribiste:
> In article <Pine.LNX.4.64.0704071129260.16935@jvz.es>, Gamo wrote:
> > sub validar {
>
> #Bien vamos a comentar perl
>
> #> my $string = $_[1];
> my $string = shift; #Best practice
>
> #> return -1 if length($string)!=7;
> #> my @s = split "", $string;
> #> my $iant="";
> #> for my $i (@s){
> #> if ($iant eq " " && $i ne " ") { return -1; }
> #> $iant=$i;
> #> }
> #> return 1;
> if (length($string) = 7) {
> $string ~= /(\S*)(\s*)/;#todo en blanco ok
> #$string ~= /(\S+)(\s*)/;#almenos un no blanco
mejor /^(\S*)(\s*)$/
> return length($1.$2) = 7;
> }else return undef;
>
>
> > }
>
>
> Hay muchismas formas de hacerlo y no creo que una regex sea la mejor
> para mi la mejor es algo parecdo a lo que Gamo escribio despues en hilo
>
> sub validar {
> my $string = shift;
> return (length($string) =7) - ($string =~ /\s\S/);
yo harĂa: length($string) == 7 and $string =~ m/^\S*\s*$/;
> }
>
> Las dos estan sin comprobar y escritas de memoria
--
Gonzalo Pérez de Olaguer Córdoba <gpoc@iies.es>
PGP key 2861C704 --- F206 5671 6789 425D 111C 1302 214F 1934 2861 C704
Technical Details
Message-ID:
<20070413004801.64ab0001@petres.salonet.snet>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news.antakira.com!cagarruta.escomposlinux.org!hercules.escomposlinux.org!escomposlinux.org!not-for-mailReferences:
<fA7Rh.3556107$D7.6476545@telenews.teleline.es> <Pine.LNX.4.64.0704071129260.16935@jvz.es> <VA.00000b9c.0184af7a@agujero-negro.escomposlinux.org>Show Full Headers
Complete Article Headers
X-Google-Thread: f86c8,dd1337191e711daf X-Google-Attributes: gidf86c8,public X-Google-Language: ENGLISH,ASCII Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news.antakira.com!cagarruta.escomposlinux.org!hercules.escomposlinux.org!escomposlinux.org!not-for-mail From: Gonzalo Pérez de Olaguer Córdoba <gpoc@iies.es> Newsgroups: es.comp.os.linux.programacion Subject: Re: Ayuda con expresiones regulares Date: Fri, 13 Apr 2007 00:48:01 +0200 Organization: escomposlinux.org Lines: 49 Message-ID: <20070413004801.64ab0001@petres.salonet.snet> References: <fA7Rh.3556107$D7.6476545@telenews.teleline.es> <Pine.LNX.4.64.0704071129260.16935@jvz.es> <VA.00000b9c.0184af7a@agujero-negro.escomposlinux.org> NNTP-Posting-Host: 84.77.244.205 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable X-Trace: hercules.cohp1 1176418083 21094 84.77.244.205 (12 Apr 2007 22:48:03 GMT) X-Complaints-To: newsmaster@news-17.escomposlinux.org NNTP-Posting-Date: Thu, 12 Apr 2007 22:48:03 +0000 (UTC) X-Newsreader: Sylpheed-Claws 1.0.4 (GTK+ 1.2.10; i386-pc-linux-gnu)