in reply to Generating a format template for a date
UPDATE: initally missed leading year format, updated code to handle it
Output:use strict; use warnings; while(<DATA>){ s/^(\d{2,4})(\D)(\d{2})(\D)(\d{4}|\d{2})/ ( length $1 > 2 ? 'YYYY' : 'DD' ) ."$2MM$4" .( length $5 > 2 ? length $1 <= 2 ? 'YYYY' : 'RR' : 'DD' )/ex; print; } __DATA__ 99/99/9999 99/99/99 99-99-9999 99-99-99 99:99:9999 99:99:99 99+99+9999 9999-99-99 9999:99:99 9999+99+99
DD/MM/YYYY DD/MM/DD DD-MM-YYYY DD-MM-DD DD:MM:YYYY DD:MM:DD DD+MM+YYYY YYYY-MM-DD YYYY:MM:DD YYYY+MM+DD
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Generating a format template for a date
by davidrw (Prior) on Oct 13, 2006 at 17:49 UTC |