Leser: 10
1 2 3 4 5 6 7 8 9
From "M/d/yyyy" to "yyyy-MM-dd": id | date id | num ---|---------- ---|----------- 1 | 1/14/2003 1 | 2003-01-14 ---|---------- ---|----------- 2 | 7/28/2004 2 | 2004-07-28 ---|---------- ---|----------- 3 | 11/8/2005 3 | 2005-11-08
s/(\d+)\/(\d+)\/(\d+)/sprintf '%d-%02d-%02d',$3,$1,$2/e
s/^(\d+)\/(\d+)\/(\d+)/sprintf '%d-%02d-%02d',$3,$1,$2/e
s/^(\d+)\/(\d+)\/(\d+)$/sprintf '%d-%02d-%02d',$3,$1,$2/e
1 2
s|(\d+)/(\d+)/(\d+)| sprintf '%d-%02d-%02d',$3,$1,$2 |e s{(\d+)/(\d+)/(\d+)}{ sprintf '%d-%02d-%02d',$3,$1,$2 }e
1 2 3 4 5 6 7 8 9
From "dd/MM/yyyy" to "yyyy-MM-dd": s/^(\d+)-(\d+)-(\d+)$/$3-$2-$1/ id | date id | num ---|----------- ---|----------- 1 | 14-01-2003 1 | 2003-01-14 ---|----------- ---|----------- 2 | 28-07-2004 2 | 2004-07-28 ---|----------- ---|----------- 3 | 08-11-2005 3 | 2005-11-08
2024-02-11T07:57:46 KuerbisDas /e habe ich weggelassen - das Beispiel soll nur zeigen, dass man im "replacement string" "captures groups" verwenden kann.
2024-02-10T16:39:12 KuerbisHallo,
welche dieser drei s///e würdet ihr für ein Beispiel in einer Dokumentation verwenden?
Code (perl): (dl )1 2 3 4 5 6 7 8 9From "M/d/yyyy" to "yyyy-MM-dd": id | date id | num ---|---------- ---|----------- 1 | 1/14/2003 1 | 2003-01-14 ---|---------- ---|----------- 2 | 7/28/2004 2 | 2004-07-28 ---|---------- ---|----------- 3 | 11/8/2005 3 | 2005-11-08
Code (perl): (dl )s/(\d+)\/(\d+)\/(\d+)/sprintf '%d-%02d-%02d',$3,$1,$2/e
Code (perl): (dl )s/^(\d+)\/(\d+)\/(\d+)/sprintf '%d-%02d-%02d',$3,$1,$2/e
Code (perl): (dl )s/^(\d+)\/(\d+)\/(\d+)$/sprintf '%d-%02d-%02d',$3,$1,$2/e