I'm not normally against ternaries, but this line is too complicated for that to still be readable (double ternary here even). Also, it would be nice to have a comment here explaining the regex.