Retina, 7171 70 bytes
Thanks to Sp3000 for saving 1 byte.
Byte count assumes ISO 8859-1 encoding. The trailing linefeed is significant.
(..)(..)$
$2$*¶$1
^
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANXDECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANXXX$2$*¶$1
+`...¶
R-6`.
Explanation
Taking 201604
as an example:
(..)(..)$
$2$*¶$1DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANXXX$2$*¶$1
This swaps the last two digits of the year with the month while also expanding the month in unary using linefeeds, and prepending the list of months in reverse so we'd get:
20¶¶¶¶1620DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANXXX¶¶¶¶16
Where the ¶
represent linefeeds (0x0A).
^
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANX
This prepends the list of all months in reverse, as well as an X (which could be anything, really):
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANX20¶¶¶¶16
+`...¶
Now we repeatedly remove three non-linefeed characters followed by a linefeed. That is we eat up the list of months from the end for each linefeed representing a month:
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANX20¶¶¶¶1620DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANXXX¶¶¶¶16
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJAN¶¶¶1620DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJAN¶¶¶16
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEB¶¶1620DECNOVOCTSEPAUGJULJUNMAYAPRMARFEB¶¶16
DECNOVOCTSEPAUGJULJUNMAYAPRMAR¶1620DECNOVOCTSEPAUGJULJUNMAYAPRMAR¶16
DECNOVOCTSEPAUGJULJUNMAYAPR1620DECNOVOCTSEPAUGJULJUNMAYAPR16
This is why we've inserted that XXXX
: since the months start counting from 1
, we'll always remove at least three characters, even for January. Two of those characters are provided by the left over part from the year, but we need to insert that X
to get to three.
R-6`.
Finally, we remove everything up to the 6th character from the end. In other words we only keep the last five characters.