Skip to content

Instantly share code, notes, and snippets.

@sironekotoro
Created July 13, 2019 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sironekotoro/e25d9d2e3c3c79880a5b14ce0fe29050 to your computer and use it in GitHub Desktop.
Save sironekotoro/e25d9d2e3c3c79880a5b14ce0fe29050 to your computer and use it in GitHub Desktop.
Perl入学式 2019第3回 即席の正規表現練習問題
#!/usr/bin/env perl
use strict;
use warnings;
my $date = '07-13-2019';
# 「2019-07-13」の形式に直す。
# 正規表現でキャプチャしたものを並べ替える
$date =~ /(\d+)-(\d+)-(\d+)/;
print $3 . '-' . $1 . '-' . $2 . "\n";
# 正規表現でキャプチャしたもので置換する
$date =~ s/(\d+)-(\d+)-(\d+)/$3-$1-$2/;
print $date . "\n";
# おまけ・正規表現を使わない方法
$date = '07-13-2019';
my @array = split /-/, $date;
my $ymd = join '-', ( $array[2], $array[0], $array[1] );
print $ymd . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment