Article View: es.comp.os.linux.programacion
Article #587Re: Ayuda con expresiones regulares
From: gamo
Date: Sat, 07 Apr 2007 10:01
Date: Sat, 07 Apr 2007 10:01
66 lines
2738 bytes
2738 bytes
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
--8323328-1014992884-1175940064=:16935
Content-Type: TEXT/PLAIN; charset=ISO-8859-1
Content-Transfer-Encoding: QUOTED-PRINTABLE
On Thu, 5 Apr 2007, F wrote:
> Hola,
>=20
> Tengo una cadena con las siguientes caracteristicas
>=20
> -El numero de caracteres siempre tiene que ser 7
> -puede tener alfanumericos y espacios, pero todos los alfanumericos que=
=20
> tengan tienen que estar al principio y todos lo espacios al final ( es de=
cir=20
> no se pueden intercarlar).
>=20
> Puede resolver estas dos condiciones por separado, pero no he conseguido=
=20
> resolverlo juntas
>=20
> =BFalguien me puede echar una mano?
>=20
> cadenas validos serian
>=20
> "a "
> "asd "
> " "
> "xxxxxxx"
>=20
> he invalidas
> "a s "
> " "
> "asas"
>=20
>=20
Si por "resolver" entiendes validar o no, puedes examinar car=E1cter
a car=E1cter y escapar en cuanto se produzca la violaci=F3n. No veo la
necesidad de utilizar expresiones regulares.
En cuanto a la violaci=F3n, entiendo que s=F3lo se produce al pasar de
espacio a no espacio, por lo que es f=E1cil de chequear.=20
sub validar {
=09my $string =3D $_[1];
=09return -1 if length($string)!=3D7;
=09my @s =3D split "", $string;
=09my $iant=3D"";
=09for my $i (@s){
=09=09if ($iant eq " " && $i ne " ") { return -1; }
=09=09$iant=3D$i;
=09}=09
=09return 1;
}
# untested=20
Saludos cordiales
--=20
http://www.telecable.es/personales/gamo/
perl -e 'print 111_111_111**2,"\n";'
--8323328-1014992884-1175940064=:16935--
Technical Details
Message-ID:
<Pine.LNX.4.64.0704071129260.16935@jvz.es>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!130.59.10.21.MISMATCH!kanaga.switch.ch!switch.ch!news.rediris.es!newsfeed.uniovi.es!newsfeed.telecable.es!cm-83-97-181-149.telecable.es!amoReferences:
<fA7Rh.3556107$D7.6476545@telenews.teleline.es>Show Full Headers
Complete Article Headers
X-Google-Thread: f86c8,dd1337191e711daf X-Google-Attributes: gidf86c8,public X-Google-Language: SPANISH,ASCII Newsgroups: es.comp.os.linux.programacion Date: Sat, 7 Apr 2007 12:01:04 +0200 From: gamo <gamo@telecable.es> X-X-Sender: amo@jvz.es Reply-To: gamo@telecable.es Subject: Re: Ayuda con expresiones regulares In-Reply-To: <fA7Rh.3556107$D7.6476545@telenews.teleline.es> Message-ID: <Pine.LNX.4.64.0704071129260.16935@jvz.es> References: <fA7Rh.3556107$D7.6476545@telenews.teleline.es> MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="8323328-1014992884-1175940064=:16935" NNTP-Posting-Host: 83.97.181.149 X-Trace: filemon1.isp.telecable.es 1175939921 83.97.181.149 (7 Apr 2007 11:58:41 +0200) Organization: TeleCable, S.A.U. Lines: 66 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!130.59.10.21.MISMATCH!kanaga.switch.ch!switch.ch!news.rediris.es!newsfeed.uniovi.es!newsfeed.telecable.es!cm-83-97-181-149.telecable.es!amo