[Nottingham] Perl Regular Expression Query.

Michael Erskine nottingham at mailman.lug.org.uk
Fri Jan 17 14:33:00 2003


This also works the same...
/@(.+?)@(.+?)@(.+?)@/
...or...
/@.+?@.+?@.+?@/
...to grab the entire string into $&


> -----Original Message-----
> From: Michael Erskine=20
> Sent: 17 January 2003 14:26
> To: nottingham@mailman.lug.org.uk
> Subject: RE: [Nottingham] Perl Regular Expression Query.
>=20
>=20
> Are the '@'s always separated by one or more character? If so...
>=20
> #!perl -w
> use strict;
>=20
> sub test {
> 	local $_ =3D shift;
> 	print "Testing '$_'...\n";
> 	if(not /@([^@]+)@([^@]+)@([^@]+)@/) {
> 		print "\tno match!\n";
> 		return;
> 	}
> 	print "\t'$1'\n\t'$2'\n\t'$3'\n";
> }
>=20
> test '@hat@coat@scarf@';
> test 'other stuff @jam@marmalade@marmite@ more stuff';
> test '@@coat@scarf@';
>=20
> __END__
>=20
> > -----Original Message-----
> > From: Robert Postill [mailto:robert.postill@ftknowledge.com]=20
> > Sent: 17 January 2003 13:29
> > To: Nottingham LUG (E-mail)
> > Subject: [Nottingham] Perl Regular Expression Query.
> >=20
> >=20
> > Hi,
> > I'm writing some Perl and want to match a string with 4 @=20
> > signs separated by a variable number of characters. =20
> > Currently I'm trying:
> > /@.*?@.*?@.*?@/
> > Which is not matching the strings properly.  Has anyone any=20
> > idea what's wrong?  More importantly has anyone got a way of=20
> > fixing it? :)
> >=20
> > Sample strings to test on are:
> > @@@@
> > one@two@three@four@
> > @a@b@c@d
> >=20
> > Cheers.
> > Robert.
> >=20
> > _______________________________________________
> > Nottingham mailing list
> > Nottingham@mailman.lug.org.uk
> > http://mailman.lug.org.uk/mailman/listinfo/nottingham
> >=20
>=20
> _______________________________________________
> Nottingham mailing list
> Nottingham@mailman.lug.org.uk
> http://mailman.lug.org.uk/mailman/listinfo/nottingham
>=20