http://qs321.pair.com?node_id=313389


in reply to Regular Expression Question

#!/usr/bin/perl use strict; use warnings; my $item = qr /(?:[Aa]|\d+(?:-\d+)?)/; my $list = qr /^$item(?:,$item)*$/; while (<DATA>) { chomp; print "$_: ", /$list/ ? "matches\n" : "does not match\n"; } __DATA__ 1 1-3 a 1,4-6,a 1,4-6,,a 1,4-6, ,1,4-6,a 1,4-6,b 1,4-6-8,a 1,4-a,2 1,4-6,4-6,1234-12,a 1: matches 1-3: matches a: matches 1,4-6,a: matches 1,4-6,,a: does not match 1,4-6,: does not match ,1,4-6,a: does not match 1,4-6,b: does not match 1,4-6-8,a: does not match 1,4-a,2: does not match 1,4-6,4-6,1234-12,a: matches
Abigail