[Nottingham] Perl Regular Expression Query.

Michael Erskine nottingham at mailman.lug.org.uk
Fri Jan 17 14:35:01 2003


Your original /@.*?@.*?@.*?@/ works OK if the fields are allowed to be
empty...
#!perl -w
use strict;

sub test {
	local $_ =3D shift;
	print "Testing '$_'...\n";
	if(not /@.*?@.*?@.*?@/) {
		print "\tno match!\n";
		return;
	}
	print "\t'$&'\n";
}

test '@hat@coat@scarf@';
test 'other stuff @jam@marmalade@marmite@ more stuff';
test '@@coat@scarf@';
test 'this definitely won\'t work!';

__END__


> -----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