in reply to Regex Modification
Use \1 to match the same delimiter:
#! perl my @should_match = ( '123-456-789', '123.789.456', '963 456 741', ); my @should_not_match = ( '123-456.789', '123 789-456', '963.456 741', ); my $re = qr/\d{3}([ .-])\d{3}\1\d{3}/; for (@should_match) { if ($_ =~ $re) { print "ok\n"; } else { print "failed\n"; } } for (@should_not_match) { if ($_ =~ $re) { print "failed\n"; } else { print "ok\n"; } }
Output:
16:53 >perl 603_SoPW.pl ok ok ok ok ok ok 16:55 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex Modification
by Anonymous Monk on Apr 10, 2013 at 07:29 UTC | |
by AnomalousMonk (Archbishop) on Apr 10, 2013 at 08:05 UTC | |
by Anonymous Monk on Apr 10, 2013 at 08:42 UTC | |
by AnomalousMonk (Archbishop) on Apr 12, 2013 at 10:09 UTC | |
by Anonymous Monk on Apr 12, 2013 at 12:35 UTC | |
| |
by si_lence (Deacon) on Apr 10, 2013 at 07:54 UTC |