Please use [] to separate the separator choices. Please consider using \A and \Z to test the entire input string. I think you meant ? rather than * for the final optional section? '?' means optionally, while * means zero or more.
use feature ":5.14"; use warnings FATAL => qw(all); use strict; use Data::Dump qw(dump); my @d = qw(26-04 26-04-12 26.04 26.04.12 30/8 30/08 30.08/12 1 12 aa a +a/bb aa.c help); say (/\A\d{2}[.-]\d{2}([.-]\d{2})?\Z/ ? "Matches for $_" : "FAILS for +$_" ) for @d;
Produces:
Matches for 26-04 Matches for 26-04-12 Matches for 26.04 Matches for 26.04.12 FAILS for 30/8 FAILS for 30/08 FAILS for 30.08/12 FAILS for 1 FAILS for 12 FAILS for aa FAILS for aa/bb FAILS for aa.c FAILS for help
In reply to Re: Regexp problem
by philiprbrenan
in thread Regexp problem
by agaved
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |